I was hoping to get some help with this piece of code.
#include <windows.h>
#include <thread>
void keyPress(WORD keyCode)
{
INPUT input;
input.type = INPUT_KEYBOARD;
input.ki.wScan = keyCode;
input.ki.dwFlags = KEYEVENTF_SCANCODE;
SendInput(1, &input, sizeof(INPUT));
}
void keyRelease(WORD keyCode)
{
INPUT input;
input.type = INPUT_KEYBOARD;
input.ki.wScan = keyCode;
input.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
SendInput(1, &input, sizeof(INPUT));
}
void CtrlPress()
{
while (true)
{
if (GetAsyncKeyState(VK_RBUTTON)) {
Sleep(1000);
keyPress(0x1D);
Sleep(3000);
keyRelease(0x1D);
}
else {
keyRelease(0x1D);;
}
}
}
int main() {
CtrlPress();
}
Essentially, what I want it to do is to press Ctrl 1000ms after I press the right mouse button, and then keep it pressed for 3000ms, and then release it, and loop as long as the right mouse button is held down. I also want the loop to immediately stop and Ctrl to be let go if the right mouse button is let go.
However, something is wrong with the code, as it drastically slows down my PC as-is.