Windows CE下的键盘钩子
2 E币
成为会员,免费下载资料
文件大小:2.21 KB
上传者:
时间:2008-08-18 22:21:13
下载量:9
在coredll.dll中有SetWindowsHookEX相关函数,这里用LoadLibrary和GetProcAddress可以调用。
以下是测试代码:
[hide]//Install the KB hook by passing the
//handle of the application to be hooked
//and the address of the KB procedure
//which will handle all the KB events
if(!ActivateKBHook(hInstance, LLKeyboardHookCallbackFunction))
{
MessageBox(GetActiveWindow(),
TEXT("Couldn't intall hook...Terminating"),
TEXT("Warning"), NULL);
exit(1);
}
//LLKeyboardHookCallbackFunction is the funtion whose
//address we passed to the system while installing the hook.
//so all the KB events will bring the control to this procedure.
//Here we want that when the user presse left or
//right key it should be interpreted as an UP key
//so now you can allow the user to configure the
//key boards the way he/she wants it
LRESULT CALLBACK LLKeyboardHookCallbackFunction(
int nCode, WPARAM wParam, LPARAM lParam)
{
if(((((KBDLLHOOKSTRUCT*)lParam)->vkCode) == VK_LEFT) ||
((((KBDLLHOOKSTRUCT*)lParam)->vkCode) == VK_RIGHT))
{
//Generate the keyboard press event of the mapped key
keybd_event(VK_UP, 0, 0, 0);
//release the mapped key
keybd_event(VK_UP, 0, KEYEVENTF_KEYUP, 0);
}
//let default processing take place
return CallNextHookEx(g_hInstalledLLKBDhook, nCode,
wParam, lParam);
}
//we are done with the hook. now uninstall it.
DeactivateKBHook();
Windows CE下的键盘钩子程序的应用这里有个例程...[/hide]
[ 本帖最后由 crystal 于 2008-8-18 22:22 编辑 ]
以下是测试代码:
[hide]//Install the KB hook by passing the
//handle of the application to be hooked
//and the address of the KB procedure
//which will handle all the KB events
if(!ActivateKBHook(hInstance, LLKeyboardHookCallbackFunction))
{
MessageBox(GetActiveWindow(),
TEXT("Couldn't intall hook...Terminating"),
TEXT("Warning"), NULL);
exit(1);
}
//LLKeyboardHookCallbackFunction is the funtion whose
//address we passed to the system while installing the hook.
//so all the KB events will bring the control to this procedure.
//Here we want that when the user presse left or
//right key it should be interpreted as an UP key
//so now you can allow the user to configure the
//key boards the way he/she wants it
LRESULT CALLBACK LLKeyboardHookCallbackFunction(
int nCode, WPARAM wParam, LPARAM lParam)
{
if(((((KBDLLHOOKSTRUCT*)lParam)->vkCode) == VK_LEFT) ||
((((KBDLLHOOKSTRUCT*)lParam)->vkCode) == VK_RIGHT))
{
//Generate the keyboard press event of the mapped key
keybd_event(VK_UP, 0, 0, 0);
//release the mapped key
keybd_event(VK_UP, 0, KEYEVENTF_KEYUP, 0);
}
//let default processing take place
return CallNextHookEx(g_hInstalledLLKBDhook, nCode,
wParam, lParam);
}
//we are done with the hook. now uninstall it.
DeactivateKBHook();
Windows CE下的键盘钩子程序的应用这里有个例程...[/hide]
[ 本帖最后由 crystal 于 2008-8-18 22:22 编辑 ]
展开》
折叠》