473,394 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

KeyDown handling?

If I press the Key "a" on the keyboard, all the events and properites will
only give me "65" as keycode.. and I want it to give me "a".

If I use the KeyPress event.. then I will have access to e.KeyChar which
will give me the "a" but I can't use that here.. I need to use the KeyDown..
since you can only capture ONE key in KeyPress and I'm looking for Several
Keys.

So I need to convert the KeyCode "65" into a Character... any ideas on how?

Regards
/Lars Netzel
Nov 20 '05 #1
9 1732

"Lars Netzel" <[stop_spam]@host.topdomain> ha scritto nel messaggio
news:eD**************@TK2MSFTNGP12.phx.gbl...
| If I press the Key "a" on the keyboard, all the events and properites will
| only give me "65" as keycode.. and I want it to give me "a".
|
| If I use the KeyPress event.. then I will have access to e.KeyChar which
| will give me the "a" but I can't use that here.. I need to use the
KeyDown..
| since you can only capture ONE key in KeyPress and I'm looking for Several
| Keys.
|
| So I need to convert the KeyCode "65" into a Character... any ideas on
how?
|
| Regards
| /Lars Netzel
|
try convert.ToChar(KeyCode)

Giuliano
Nov 20 '05 #2
> If I press the Key "a" on the keyboard, all the events and properites will
only give me "65" as keycode.. and I want it to give me "a".

If I use the KeyPress event.. then I will have access to e.KeyChar which
will give me the "a" but I can't use that here.. I need to use the KeyDown.. since you can only capture ONE key in KeyPress and I'm looking for Several
Keys.

So I need to convert the KeyCode "65" into a Character... any ideas on how?
Regards
/Lars Netzel

if i understood well your questions you can do
Chr(e.KeyCode)

Bye
--
Ciao

::P:e:s:c:e:::M:a:r:c:o::
it***************@hotmail.com
per contatti PVT elinimare NOSPAM
Nov 20 '05 #3
"Lars Netzel" <[stop_spam]@host.topdomain> schrieb
If I press the Key "a" on the keyboard, all the events and properites
will only give me "65" as keycode.. and I want it to give me "a".

If I use the KeyPress event.. then I will have access to e.KeyChar
which will give me the "a" but I can't use that here.. I need to use
the KeyDown.. since you can only capture ONE key in KeyPress and I'm
looking for Several Keys.

So I need to convert the KeyCode "65" into a Character... any ideas
on how?


If you want to process chars, use KeyPress.
If you want to process keys, use KeyDown.

Why can't you use
if e.keycode = System.Windows.Forms.Keys.A then
?
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
Yes, thank you! It fixed my problem!

/Lars

"::P:e:s:c:e:::M:a:r:c:o::" <it***************@hotmail.com> skrev i
meddelandet news:uk****************@TK2MSFTNGP09.phx.gbl...
If I press the Key "a" on the keyboard, all the events and properites will only give me "65" as keycode.. and I want it to give me "a".

If I use the KeyPress event.. then I will have access to e.KeyChar which
will give me the "a" but I can't use that here.. I need to use the

KeyDown..
since you can only capture ONE key in KeyPress and I'm looking for Several Keys.

So I need to convert the KeyCode "65" into a Character... any ideas on

how?

Regards
/Lars Netzel

if i understood well your questions you can do
Chr(e.KeyCode)

Bye
--
Ciao

::P:e:s:c:e:::M:a:r:c:o::
it***************@hotmail.com
per contatti PVT elinimare NOSPAM

Nov 20 '05 #5
Cause I have dynamic Hotkeys... the user can choose what To compare with so
I can's use the static comparision you suggested.

/Lars

"Armin Zingler" <az*******@freenet.de> skrev i meddelandet
news:40***********************@news.freenet.de...
"Lars Netzel" <[stop_spam]@host.topdomain> schrieb
If I press the Key "a" on the keyboard, all the events and properites
will only give me "65" as keycode.. and I want it to give me "a".

If I use the KeyPress event.. then I will have access to e.KeyChar
which will give me the "a" but I can't use that here.. I need to use
the KeyDown.. since you can only capture ONE key in KeyPress and I'm
looking for Several Keys.

So I need to convert the KeyCode "65" into a Character... any ideas
on how?


If you want to process chars, use KeyPress.
If you want to process keys, use KeyDown.

Why can't you use
if e.keycode = System.Windows.Forms.Keys.A then
?
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #6
"Lars Netzel" <[stop_spam]@host.topdomain> schrieb
"Lars Netzel" <[stop_spam]@host.topdomain> schrieb
If I press the Key "a" on the keyboard, all the events and
properites will only give me "65" as keycode.. and I want it to
give me "a".

If I use the KeyPress event.. then I will have access to
e.KeyChar which will give me the "a" but I can't use that here..
I need to use the KeyDown.. since you can only capture ONE key in
KeyPress and I'm looking for Several Keys.

So I need to convert the KeyCode "65" into a Character... any
ideas on how?


If you want to process chars, use KeyPress.
If you want to process keys, use KeyDown.

Why can't you use
if e.keycode = System.Windows.Forms.Keys.A then
?


Cause I have dynamic Hotkeys... the user can choose what To compare
with so I can's use the static comparision you suggested.


I don't understand. You can also use a variable of type
System.Windows.Forms.Keys instead of directly using the constant to compare
to.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #7
The user fill a textfield in the preferences window of my application with
what letters (+ ALT) associated they want to use for certain functions.
Since that's a String I get from the USer I nee to get that into something
that I can compare with in the Event for the KeyDown.

If you know of a really good way of doing this without using my way I'm
happy to hear cause my solution feels a bit "ugly"

If Chr(e.KeyValue) = UserVariableAsString AndAlso (e.Alt) Then

Me.dgrResources.Focus()

ElseIf Chr(e.KeyValue) = UserVariableAsString2 AndAlso e.Modifiers =
Keys.Alt Then

Me.dgrCodes.Focus()

End If

/Lars Netzel

"Armin Zingler" <az*******@freenet.de> skrev i meddelandet
news:40***********************@news.freenet.de...
"Lars Netzel" <[stop_spam]@host.topdomain> schrieb
"Lars Netzel" <[stop_spam]@host.topdomain> schrieb
> If I press the Key "a" on the keyboard, all the events and
> properites will only give me "65" as keycode.. and I want it to
> give me "a".
>
> If I use the KeyPress event.. then I will have access to
> e.KeyChar which will give me the "a" but I can't use that here..
> I need to use the KeyDown.. since you can only capture ONE key in
> KeyPress and I'm looking for Several Keys.
>
> So I need to convert the KeyCode "65" into a Character... any
> ideas on how?

If you want to process chars, use KeyPress.
If you want to process keys, use KeyDown.

Why can't you use
if e.keycode = System.Windows.Forms.Keys.A then
?
Cause I have dynamic Hotkeys... the user can choose what To compare
with so I can's use the static comparision you suggested.


I don't understand. You can also use a variable of type
System.Windows.Forms.Keys instead of directly using the constant to

compare to.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #8
"Lars Netzel" <[stop_spam]@host.topdomain> schrieb
Cause I have dynamic Hotkeys... the user can choose what To
compare with so I can's use the static comparision you
suggested.


I don't understand. You can also use a variable of type
System.Windows.Forms.Keys instead of directly using the constant
to

compare
to.

The user fill a textfield in the preferences window of my application
with what letters (+ ALT) associated they want to use for certain
functions. Since that's a String I get from the USer I nee to get
that into something that I can compare with in the Event for the
KeyDown.

If you know of a really good way of doing this without using my way
I'm happy to hear cause my solution feels a bit "ugly"

If Chr(e.KeyValue) = UserVariableAsString AndAlso (e.Alt) Then

Me.dgrResources.Focus()

ElseIf Chr(e.KeyValue) = UserVariableAsString2 AndAlso e.Modifiers
= Keys.Alt Then

Me.dgrCodes.Focus()

End If

Dim key As System.Windows.Forms.Keys
key = DirectCast( _
[Enum].Parse( _
GetType(System.Windows.Forms.Keys), "a", True _
), System.Windows.Forms.Keys _
)
But, instead of offering a way to input chars, I'd handled the KeyDown
event. Open the properties of a link in the explorer where you can input a
key combination. That's probably something I'd prefer as a user.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #9
Lars,
I would consider creating a custom control for your preferences window that
has a property of type System.Windows.Forms.Keys that represents the key the
user presses.

The control would display a text representation of this using Enum.ToString.

The control would use the KeyDown event to store the keys used to create the
value.

This control would work similar to the "Press shortcut keys(s)" control in
"Tools - Customize - Keyboard" in VS.NET.

Hope this helps
Jay

"Lars Netzel" <[stop_spam]@host.topdomain> wrote in message
news:Oo**************@tk2msftngp13.phx.gbl...
The user fill a textfield in the preferences window of my application with
what letters (+ ALT) associated they want to use for certain functions.
Since that's a String I get from the USer I nee to get that into something
that I can compare with in the Event for the KeyDown.

If you know of a really good way of doing this without using my way I'm
happy to hear cause my solution feels a bit "ugly"

If Chr(e.KeyValue) = UserVariableAsString AndAlso (e.Alt) Then

Me.dgrResources.Focus()

ElseIf Chr(e.KeyValue) = UserVariableAsString2 AndAlso e.Modifiers =
Keys.Alt Then

Me.dgrCodes.Focus()

End If

/Lars Netzel


<<snip>>
Nov 20 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: Andrew DeFaria | last post by:
I thought this would be fairly straight forward but apparently it's not. Given the following html file: <!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en"> <html> <head>...
3
by: bardo | last post by:
I have a Datagrid that is inside a panel. I want to use the keyDown event to reconize the arrow keys. But I have no luck at all. The problem is that the keydown event won't fire at all, unless I...
2
by: ZS | last post by:
Hi, On a form , I'm trying to trap when a shift key is pressed. Can someone explain how the KeyUp,KeyDown and Key Press event works for Forms. Thanks -ZS
0
by: Eddie | last post by:
Hi All, I'm having a little problem with the KeyDown event handler. I have added a keydown event handler to my Form, but the ToolBar control is overriding it. So say I press the arrow keys,...
0
by: tony | last post by:
Hello!! I have a derived class called StringClassEditor which inherit from UITypeEditor listed below. Now to my question in method EditValue in this class I have this statement lb.KeyDown ...
3
by: MLM450 | last post by:
I have a control that handles the KeyDown event but it does not seem to execute when a combination of keys is pressed - like CTRL+Z. If I press CTRL, it executes. If I press Z, it executes. But the...
3
by: Luc The Perverse | last post by:
Hey - I am making my first C# form application! (More a teach myself app than any pratical application) I have a listbox that always has the control so I made an event handler for KeyDown. I...
14
by: raylopez99 | last post by:
KeyDown won't work KeyPress fails KeyDown not seen inspired by a poster here:http://tinyurl.com/62d97l I found some interesting stuff, which I reproduce below for newbies like me. The main...
4
by: Tom P. | last post by:
You wouldn't think this would be as hard as it is but for some reason I can't find a way to translate any of the codes in the KeyDownEventArgs into the actual characters they represent. The best...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.