Julia
Julia

Reputation: 11

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 WaitForMultipleObjects(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?

Upvotes: 1

Views: 975

Answers (3)

MSalters
MSalters

Reputation: 179799

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

Upvotes: 1

Shahbaz
Shahbaz

Reputation: 47503

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.

Upvotes: 0

Daniel A. White
Daniel A. White

Reputation: 190935

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

Upvotes: 0

Related Questions