Created
April 11, 2016 16:30
-
-
Save sontx/cd6ae3334783aa6a032be0dcc9ce3de9 to your computer and use it in GitHub Desktop.
using keybd_event to send virtual key code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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