I'm trying to get a char converted to System.windows.Form.Keys type or a string to a Keys array. Does anyone know how to do it in a simple way?
Asked
Active
Viewed 3,193 times
1 Answers
4
The Keys
codes for the numbers and uppercase letters match the corresponding ASCII codes. Assuming you're dealing with ASCII, you can do:
Keys key = (Keys) (byte) char.ToUpper(c);

Tim Robinson
- 53,480
- 10
- 121
- 138
-
How do you do this if it's not w/in that range? – Geesu Nov 13 '12 at 23:57
-
@Geesu, the `Keys` type only contains the uppercase letters and the numbers from a US keyboard. Non-ASCII characters, lowercase letters and symbols will vary for different keyboard layouts. If you want to use non-ASCII letters then you'll need to use something else. – Tim Robinson Nov 14 '12 at 13:19