KeyDown handling?

  • Thread starter Thread starter Lars Netzel
  • Start date Start date
L

Lars Netzel

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
 
"Lars Netzel" <[stop_spam]@host.topdomain> ha scritto nel messaggio
| 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
 
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::
(e-mail address removed)
per contatti PVT elinimare NOSPAM
 
Lars Netzel said:
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
 
Yes, thank you! It fixed my problem!

/Lars

::P:e:s:c:e:::M:a:r:c:o:: said:
if i understood well your questions you can do
Chr(e.KeyCode)



Bye
--
Ciao

::P:e:s:c:e:::M:a:r:c:o::
(e-mail address removed)
per contatti PVT elinimare NOSPAM
 
Cause I have dynamic Hotkeys... the user can choose what To compare with so
I can's use the static comparision you suggested.

/Lars
 
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
 
Lars Netzel said:
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
 
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 said:
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>>
 
Back
Top