C# – Convert A Char To Keys


I have a special char (/ @) That I want to convert to Keys.

I am currently using this :

Keys k = (Keys)'/';

And while debugging, I get that k equals to :

LButton | RButton | MButton | Back | Space type – System.Windows.Forms.Keys

k's keycode was suppose to be 111.

NOTE: The code does work for uppercase letters such as :

Keys k = (Keys)'Z';

In that case, k's key code is 90, which is ok.

I'm trying to find a way to convert special chars to Keys. (or to their proper key code)

Trying to send keys globally using :

public static void SendKey(byte keycode)
        const int KEYEVENTF_EXTENDEDKEY = 0x1;
        const int KEYEVENTF_KEYUP = 0x2;
        keybd_event(keycode, 0x45, KEYEVENTF_EXTENDEDKEY, (UIntPtr)0);
        keybd_event(keycode, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, (UIntPtr)0);


Best Solution

It's old question, but I used this:

Keys k = (Keys)char.ToUpper(c);

If char value is a (with code 97) then converting into A (with code 65) maps to Keys.A and so on...

Hope this will help someone.