Nicholas Tsipanov (nicholas@spbteam.com), January 22, 2004.
I have added the code to handle hardware button events on Pocket PC. There are WM_KEYUP messages coming to my control but no WM_KEYDOWN has been caught. How can I get WM_KEYDOWN messages?
Actually you can't. But you can fake it.
The system won't send you the WM_KEYDOWN message for Pocket PC hardware key events. It sends WM_HOTKEY instead and in sometimes WM_KEYUP message.
I would suggest you to read other related articles on Pocket PC DN site before further reading because I will assume that you know all the stuff about RegisterHotKey function.
So after you successfully registered the hardware keys with RegisterHotKey call you have to handle WM_HOTKEY message. Windows will send you this message all the time while the user holds the hardware button. So we have to find the moments when the user just pressed the button and when he or she just released it.
With release its easy: as a last event Windows will send MOD_KEYUP flag in fuModifiers parameter if you called RegisterHotKey in this way:
I have added different way to call of this function in the sample application (API sample for purists is here ).
But what to do with the first event?
Here we will use local static flag variable indicating that the user pressed and still holding the button:
Another slightly unrelated note: when you application loses focus (or disappears from top which is same for Pocket PC) you will get you keys unregistered, so it's better to handle WM_ACTIVATE to re-register those keys again:
Sample code for this article: sample with MFC, and a sample without MFC.