-
[RESOLVED] Keys to Char?
Hi,
In KeyDown event, one can check the pressed key by looking at e.KeyValue/KeyCode, but since there are two sets of numeric keys (one is in the keypad and another is above the letter keys), they have differencen KeyCode, e.g. for number "1", e.KeyCode would either equals to Keys.D1 or Keys.NumPad1. What I'm interested is only the char "1", so is there any efficient way to obtain a single char for the key that being pressed?
I tried
KeyInChar = Convert.ToChar(e.KeyValue)
but it is not correct
Any help would be appreciated!
-
Re: Keys to Char?
Im pretty sure you just have to make a case for numpad1 OR d1
-
Re: Keys to Char?
It sounds to me like you should be handling the KeyPress event instead. The KeyDown and KeyUp events relate to individual kays on the keyboard, while the KeyPress event relates to input characters. Note that if you use the KeyDown event you'd also have to test the modifier keys because if the Shift key is depressed then pressing the "1" key won't produce the character "1" but an exclamation mark instead. In the KeyPress event it would simply be:
-
Re: Keys to Char?
Thanks for the suggestions!! They solved my problem.