I want to create a program which sends exactly one key stroke for every key stroke I press. I'm having a problem with this program because it keeps sending keystrokes even after I stopped pressing the key.
For example; if pressed "UP", it will continue pressing up until i press another key.
Can you help me with this please.
Thank you
int main()
{
// This structure will be used to create the keyboard
// input event.
INPUT ip;
while(1)
{
if (GetAsyncKeyState(VK_UP) < 0)
{
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = 0x26; // virtual-key code for the "UP arrow" key
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));
}
if (GetAsyncKeyState(VK_DOWN) < 0)
{
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = 0x28; // virtual-key code for the "UP arrow" key
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));
}
if (GetAsyncKeyState(VK_RIGHT) < 0)
{
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.time = 0;
ip.ki.wVk = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = 0x27; // virtual-key code for the "UP arrow" key
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));
}
if (GetAsyncKeyState(VK_LEFT) < 0)
{
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = 0x25; // virtual-key code for the "UP arrow" key
ip.ki.dwFlags = 0; // 0 for key press
SendInput(1, &ip, sizeof(INPUT));
}
}
// Exit normally
return 0;
}