const int KEYEVENTF_KEYPRESS = 0x0000;
const int KEYEVENTF_KEYUP = 0x0002;
[DllImport("coredll.dll")]
static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
void SendKey(Keys key)
{
keybd_event((byte) key, 0, KEYEVENTF_KEYPRESS, 0);
keybd_event((byte) key, 0, KEYEVENTF_KEYUP, 0);
}
The code above will send the keyboard event to currently focused window or control
No comments:
Post a Comment