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 );
Use this to determine if the button is pressed.
if((GetKeyState(VK_LBUTTON) & 0x8000) != 0)
http://vcpptips.wordpress.com/tag/vk_lbutton/
The application can catch messages and process being sent to your window indicating a state change of any mouse button.
When the left button is pressed a
WM_LBUTTONDOWN
is sent.
When it is released
WM_LBUTTONUP
is sent.
Please read here for various messages being sent to indicate mouse events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With