As its a KeyCode
cast to the Keys
enum?
((Keys)e.KeyValue).ToString();
Domanda
when I press F2 then following code in my form keydown event return 113
MessageBox.Show(e.KeyValue.ToString());//If pressed key is F2 ->113
but when I want to get the Char from KeyValue from following code then it return "q"
MessageBox.Show(Char.ConvertFromUtf32(113));//return q
how can I reach to F2 from 113 keyvalue ?
Soluzione
As its a KeyCode
cast to the Keys
enum?
((Keys)e.KeyValue).ToString();
Altri suggerimenti
Typically, the function keys are not actually characters. Frequently, they are mapped as key combinations, like (0, 113). Why do you want the character code for F2?
The reason you are getting the letter q when you try and get the char value of 113 is because it maps to the ASCII value of q
And to answer the rest of your question
I found this article here http://bytes.com/topic/c-sharp/answers/429451-keycode-keyvalue-keydata
There are KeyUp, KeyDown and KeyPress event. Only the KeyPress event supplies the character code. I don't say ASCII because this code depends on the current language settings; even one code can be generated as a result of pressing a sequence of keys. Even in the simplest cases with English language settings there is no 1:1 mapping between keys and character codes e.g. key A produces ASCII for 'a' or key A produces ASCII for 'A' if cpaslock is on or shift is pressed or 'a' of both capslock is on and shift is pressed, etc. Even more there are keys that don't produce ASCII codes - ctrl, alt, shift, F1, F2., Fx, windows keys, etc