keybd_event is not working right =(

Posted by user302131 on Stack Overflow See other posts from Stack Overflow or by user302131
Published on 2010-04-02T02:07:50Z Indexed on 2010/04/02 6:03 UTC
Read the original article Hit count: 270

Filed under:
|
|
|

I can't get this to work right. This should press left for 1 second then wait 10 seconds, then right 1 second, etc.:

keybd_event(0x25, 0xCB, 0, 0);  // press left
cout << "Ldown\n";              // so i know it worked

Sleep(1000);                    // hold it for 1sec
keybd_event(0x25, 0xCB, KEYEVENTF_KEYUP, 0);// let go of the key
cout << "Lup\n";                // so i know i let go
Sleep(10000);                   // Sleep for 10secs

keybd_event(0x27, 0xCD, 0, 0);  // press right
cout << "Rdown\n";              // so i know i pressed right
Sleep(1000);                    // sleep 1sec
keybd_event(0x27, 0xCD, KEYEVENTF_KEYUP, 0);// let go of the key
cout << "Rdown\n";              // so i know i let go.

This is in a loop but it wont do anything :( Unless I close the program before the key is let go, then it will just keep the key down until I press the key again.

I know you can use only one key code if you want but I need to use both.

So what am I missing?

© Stack Overflow or respective owner

Related posts about c++

Related posts about keyboard