Skip to content

Instantly share code, notes, and snippets.

@sontx
Created April 11, 2016 16:30
Show Gist options
  • Save sontx/cd6ae3334783aa6a032be0dcc9ce3de9 to your computer and use it in GitHub Desktop.
Save sontx/cd6ae3334783aa6a032be0dcc9ce3de9 to your computer and use it in GitHub Desktop.
using keybd_event to send virtual key code
using System;
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
void PressKey(byte keyCode)
{
const int KEYEVENTF_EXTENDEDKEY = 0x1;
const int KEYEVENTF_KEYUP = 0x2;
keybd_event(keyCode, 0x45, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(keyCode, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
}
// to send backspace key use: PressKey((byte) '\b');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment