Programmatically send keystrokes to active current window in Windows



Here is the code to send keys (key strokes) to active current application in Windows using C++/Win API.

void SendKey(WORD wVkey)
{
	INPUT inputs[2];
	inputs[0].type = inputs[1].type = INPUT_KEYBOARD;
	inputs[0].ki.dwExtraInfo = inputs[1].ki.dwExtraInfo = 0;
	inputs[0].ki.wVk = inputs[1].ki.wVk = wVkey;
	inputs[0].ki.dwFlags = 0;
	inputs[1].ki.dwFlags = KEYEVENTF_KEYUP;
 
	SendInput(2, inputs, sizeof(INPUT));
}

Leave a Reply

Your email address will not be published. Required fields are marked *