| Gonen (47) | |||
|
Hey. I've created a window class which should print "Control key pressed" each time the control key is being pressed. To do that , I need to handle the WM_KEYDOWN message. This is what I wrote
*as you can see , my window is a message-only window. My code doesn't work, I don't know why. Any suggestions ? | |||
|
|
|||
| chris (82) | |||
This has me baffled, however, I kinda have a solution...
Note the additions of "HWND hwnd;" & then "hwnd = Create..." Now... this works for me but only when I first execute the program, & the console window top doesn't turn blue (for active window), but it is on top of all others... I will keep trying to solve this properly... | |||
|
|
|||
| Gonen (47) | |
|
Thank you , it worked. But as you said , this code works only if the focus is on program's window. Is there anyway to do it when the focus isn't on the specific window ? (i.e. to print "Control key pressed" whenever the user presses the Control key , even if the focus isn't on the specific window I've created) | |
|
|
|
| chris (82) | |
|
If you mean when for example, the console is minised I suggest you look here: http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx - for the MSDN documentation about the GetAsyncKeyState function & also here - http://www.cplusplus.com/forum/windows/6632/ - for another thread about this function. | |
|
|
|
| Gonen (47) | |
|
I know about the GetAsyncKeyState function. I am working on a program right now, and I need to create a message-only window there. So how should I use the GetAsyncKeyState function there? I mean , It need to be used in a loop , and I can't use it in the message loop.. | |
|
|
|
| chris (82) | |||
|
Well one way (seeing as we are using WIN API for this) is to use the Windows function to multi-thread our program, basically make it do more than one thing "at once" (well, pretty much at once). This can be achieved using the function CreateThread (http://msdn.microsoft.com/en-us/library/ms682453(VS.85).aspx ). I made this example & I hope it helps:
Let me know if you need anything else | |||
|
Last edited on
|
|||
| Gonen (47) | |
|
It worked. Thank you very very much. | |
|
|
|
| chris (82) | |
| No problems mate - any time =) | |
|
|
|