Reputation: 21
On your device running win CE 6.0 is a button, and you need to catch the moment when it is pressed. That is, until we press the button, our method is performed, released - stop method. Please help with the solution of the problem.
Upvotes: 2
Views: 642
Reputation: 1244
Here is a link to codeproject with source code to do what you want:
http://www.codeproject.com/Articles/49881/Hooking-the-keyboard-message-queue-in-compact-fram
I have used this code successfully in my own WM project to re-purpose volume keys and a few other hardware buttons (I use volume up/down on one screen as a trigger to flip the screen orientation).
There is too much code to post here. in the project is vkmap.cs which appears to be a comprehensive listing of all the keys available:
public static vkMap[] vkValues = {
new vkMap ( 0x00, "VK_NOTDEF"),
new vkMap ( 0x01, "VK_LBUTTON" ),
new vkMap ( 0x02,"VK_RBUTTON" ),
new vkMap ( 0x03,"VK_CANCEL" ),
...
new vkMap ( 0x30,"VK_0" ),
new vkMap ( 0x31,"VK_1" ),
...
new vkMap ( 0x41,"VK_A" ),
...
new vkMap ( 0xA6,"VK_BROWSER_BACK" ),
new vkMap ( 0xA7,"VK_BROWSER_FORWARD" ),
new vkMap ( 0xA8,"VK_BROWSER_REFRESH" ),
and so on.. all in all some 258 keys however some are marked as undefined.
To use the code:
HookKeys hook = new HookKeys();
hook.HookEvent += new HookKeys.HookEventHandler(HookEvent);
hook.Start();
Then in your eventHandler code as you wish - I used a Switch statement to find the keys I wanted:
switch (vkMap.vkValues[keyBoardInfo.vkCode].s)
{
case "VK_F6":
if ((hookArgs.wParam.ToInt32() == WM_KEYDOWN) || (hookArgs.wParam.ToInt32() == WM_SYSKEYDOWN))
// Code here
break;
case "VK_F7":
if ((hookArgs.wParam.ToInt32() == WM_KEYDOWN) || (hookArgs.wParam.ToInt32() == WM_SYSKEYDOWN))
// Code here
break;
default:
break;
}
I can't recall why i'm also checking WM_KEYDOWN and WM_SYSKEYDOWN.. sorry about that; If I remember i'll post an edit.
And when you're finished needing input:
hook.Stop();
Upvotes: 2