I am trying to get a small app that will continuously simulate UP (↑ arrow key) while another key is pressed, in my case Right CTRL.
The code I wrote however, will only send one UP for each press - and while I keep Right CTRL pressed, it will only send one UP and stop.
I want to mention that this code is built entirely from documentation I found online, I have never written anything in C++ ever before, or any other language so any suggestions would greatly help me. I initially tried doing this while CAPS LOCK was active, but I found that getting the key state (on/off) did not work for me at all, no matter what I tried.
int main()
{
// This structure will be used to create the keyboard
// input event.
INPUT ip;
// Pause for 1 seconds.
Sleep(1000);
// Set up a generic keyboard event.
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0; // hardware scan code for key
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
while(1){
if(GetAsyncKeyState(VK_RCONTROL))
{
// Press the "UP arrow" key
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));
Sleep(50);
// Release the "UP arrow" key
ip.ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP for key release
SendInput(1, &ip, sizeof(INPUT));
Sleep(50);
}
}
// Exit normally
return 0;
}