blah blah blah is here! blah blah » Close

268 views

send keys

up0down
link

hi with the SendKeys.Send("{ENTER}"); i send the enter key

i wand to send the key using the keynumber not the name...

any idea?

last answered 2 years ago

1 answers

up0down
link

If by key number you mean the virual key code (13 in the case of ENTER), then the easiest way is to use the API function keybd_event:

using System.Runtime.InteropServices;


// declarations


[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, UIntPtr dwExtraInfo);

const uint KEYEVENTF_EXTENDEDKEY = 0x01;
const uint KEYEVENTF_KEYUP = 0x02;
const byte VK_RETURN = 0x0D;


// send ENTER key with


keybd_event( VK_RETURN, 0x45, KEYEVENTF_KEYUP, UIntPtr.Zero );

There's a list of virtual keycodes here.

Feedback