I've setup 2 functions to simulate keyboard button presses
void KeyboardButtonDown(DWORD a)
{
INPUT Input = { 0 };
// Set up a generic keyboard event.
Input.type = INPUT_KEYBOARD;
Input.ki.wVk = a;
SendInput(1, &Input, sizeof(INPUT));
}
void KeyboardButtonUp(DWORD a)
{
INPUT Input = { 0 };
Input.type = INPUT_KEYBOARD;
Input.ki.dwFlags = KEYEVENTF_KEYUP;
Input.ki.wVk = a;
SendInput(1, &Input, sizeof(INPUT));
}
It works in most cases, however it fails in some apps when simulating arrow keys, as a simple exampe
KeyboardButtonDown(VK_LEFT);
Sleep(50);
KeyboardButtonUp(VK_LEFT);
Sleep(50);
It works in notepad but when playing a game it does nothing. I've mapped the controls in game to use other keys instead and it then works fine.
What am I doing wrong here?