Jan Tacci
Jan Tacci

Reputation: 3211

ASCII Values For Keyboard Key Press Events?

I borrowed someones code that sends a key event to another process (hWnd). Here is the definition of that function:

public static void SendKey(ushort key, IntPtr hWnd)
{
    SetActiveWindow(hWnd);
    SendMessage(hWnd, WM_KEYDOWN, key, 0);
    SendMessage(hWnd, WM_KEYUP, key, 0);
}

Where SendMessage is taken from a DllImport:

//sends a windows message to the specified window
[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, uint wParam, int lParam);

As you can see, the SendKey method takes a ushort value for the key to be sent.

Does anyone know where I can find these values? I.e. if the user pressed the "7" key and I wanted to forward it how to i go from the 7 key event/callback to a ushort value?

Thanks!

Upvotes: 0

Views: 4903

Answers (2)

Spontifixus
Spontifixus

Reputation: 6660

You could try the Keys-Enumeration...

Upvotes: 1

Krešimir Lukin
Krešimir Lukin

Reputation: 399

For sending ascii characters you can use type casting, here is the example:

System.Convert.ToUInt16('7')

For sending non ascii characters use virtual key codes. Reference can be found at MSDN

Upvotes: 0

Related Questions