I am new to c++ and I am trying to activate a line of code only when the left mouse button is held down. In this example, my code works but it seems that it just toggles it. When I click, it spams the H key then, when I click again, it stops.
Currently I have this code:
if ((GetKeyState(VK_LBUTTON)))
{
keybd_event(VkKeyScan('H'),0,0,0);
Sleep ( 30 );
}
Edit:
I have inside the function:
int WINAPI WinMain ( HINSTANCE hInst, HINSTANCE P, LPSTR CMD, int nShowCmd );
See Question&Answers more detail:os