开发者

Keyevent in Windows

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜