问题
In my KeyDown
EventHandler
I need to know what is the KeyCode
for "," and ".".
I can't find them thats why I ask. Thanks!
回答1:
A key and a character are not the same thing. The keyboard layout transforms between them, and that transform isn't trivial. Probably you're doing the wrong thing when using KeyDown
. If you want to know which character a user entered you should use KeyPress
, which gives the the already translated character.
For example Keys.Decimal
is a key on the numpad that corresponds to .
on the US layout, and ,
on the German layout. Keys.Oemcomma
and OemPeriod
are likely ,
and .
belows the letters. But on other layouts that may be different.
回答2:
Oemcomma
and OemPeriod
look like good candidates.
Look at the Keys enumeration on MSDN.
回答3:
I did this:
- Created a WinForm project with a single textbox.
- Added the keydown event handler.
- Put a break point in it
- Got this:

回答4:
Check out the decimal value, that's your key code.
http://www.asciitable.com/
回答5:
Use Keys.Oemcomma
and Keys.OemPeriod
回答6:
Have you tried this "."c
A float filter:
Select Case e.KeyChar
Case "0"c To "9"c
Case "."c
If .Text.Contains(".") Then
e.Handled = True
End If
Case ChrW(Keys.Delete), ChrW(Keys.Back)
Case Else
e.Handled = True
End Select
来源:https://stackoverflow.com/questions/8915626/what-is-the-keycode-for-comma-and-dot-in-net