|
-
Dec 5th, 2006, 11:31 AM
#1
Thread Starter
Member
[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!
Last edited by LazNiko; Dec 5th, 2006 at 11:38 AM.
-
Dec 5th, 2006, 12:05 PM
#2
Junior Member
Re: Keys to Char?
Im pretty sure you just have to make a case for numpad1 OR d1
-
Dec 5th, 2006, 06:37 PM
#3
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:
-
Dec 6th, 2006, 02:24 AM
#4
Thread Starter
Member
Re: Keys to Char?
Thanks for the suggestions!! They solved my problem.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|