开发者

Keyevent in Windows

开发者 https://www.devze.com 2023-04-02 05:13 出处:网络
is it possible to get an event for pressed key in Windows (XP)? I have a thread, it has a while(1)-loopand i print some data there. It must be synchronize thats why i use WaitForMultiple开发者_高级运维

is it possible to get an event for pressed key in Windows (XP)? I have a thread, it has a while(1)-loop and i print some data there. It must be synchronize thats why i use WaitForMultiple开发者_高级运维Objects(2, events, FALSE, INFINITE); events is an array of handles and it contains 2 handles. One of them is an event from the other thread that signals, that the server got a new message and the other one should signal me that the user pressed a key (1-7). How can i get this second handle/event?


You're looking for MsgWaitForMultipleObjects. This can retrieve messages as well, such as WM_KEYDOWN. You don't need a HANDLE for key events.


You have to implement a message loop to listen for WM_KEYDOWN or WM_KEYUP. Then you should call the appropriate method.


In your program, you should have a thread handling events arriving to your program, such as keyboard, mouse etc. In that thread, you can detect if a keyboard event pressing or releasing the key you are interested in arrives. If so, you signal your other thread.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号