Lazarus中文社区

 找回密码
 立即注册(注册审核可向QQ群索取)

QQ登录

只需一步,快速开始

Lazarus IDE and 组件 下载地址版权申明
查看: 7053|回复: 4

那位高手会wince键盘钩子

[复制链接]

该用户从未签到

发表于 2009-11-11 10:53:43 | 显示全部楼层 |阅读模式
那位高手会贴出来吧
回复

使用道具 举报

该用户从未签到

 楼主| 发表于 2009-11-12 13:36:28 | 显示全部楼层

自己的问题自己搞定

自己搞定了,网上说的回调函数必须放在dll中很繁琐,其实可以直接放在一起。
wince做嵌入式设备很需要键盘钩子的。
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2009-12-4 11:45:24 | 显示全部楼层

Re:自己的问题自己搞定

引用第1楼tsp_1030于2009-11-12 13:36发表的 自己的问题自己搞定 :
自己搞定了,网上说的回调函数必须放在dll中很繁琐,其实可以直接放在一起。
wince做嵌入式设备很需要键盘钩子的。
分享一下你的结果那
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2010-1-13 16:00:25 | 显示全部楼层
  1. 在coredll.dll中有SetWindowsHookEX相关函数,这里用LoadLibrary和GetProcAddress可以调用。
  2. 以下是测试代码:
  3. //Install the KB hook by passing the
  4. //handle of the application to be hooked
  5. //and the address of the KB procedure
  6. //which will handle all the KB events
  7. if(!ActivateKBHook(hInstance, LLKeyboardHookCallbackFunction))
  8. {
  9.     MessageBox(GetActiveWindow(),
  10.         TEXT("Couldn't intall hook...Terminating"),
  11.         TEXT("Warning"), NULL);
  12.     exit(1);
  13. }
  14. //LLKeyboardHookCallbackFunction is the funtion whose
  15. //address we passed to the system while installing the hook.
  16. //so all the KB events will bring the control to this procedure.
  17. //Here we want that when the user presse left or
  18. //right key it should be interpreted as an UP key
  19. //so now you can allow the user to configure the
  20. //key boards the way he/she wants it
  21. LRESULT CALLBACK LLKeyboardHookCallbackFunction(
  22.                   int nCode, WPARAM wParam, LPARAM lParam)
  23. {
  24.     if(((((KBDLLHOOKSTRUCT*)lParam)->vkCode) == VK_LEFT) ||
  25.            ((((KBDLLHOOKSTRUCT*)lParam)->vkCode) == VK_RIGHT))
  26.     {
  27.         //Generate the keyboard press event of the mapped key
  28.         keybd_event(VK_UP, 0, 0, 0);
  29.         //release the mapped key
  30.         keybd_event(VK_UP, 0, KEYEVENTF_KEYUP, 0);
  31.     }
  32.     //let default processing take place
  33.     return CallNextHookEx(g_hInstalledLLKBDhook, nCode,
  34.                                               wParam, lParam);
  35. }
  36. //we are done with the hook. now uninstall it.
  37. DeactivateKBHook();
复制代码
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2010-9-3 13:09:15 | 显示全部楼层
这            谢谢哈
回复 支持 反对

使用道具 举报

*滑块验证:

本版积分规则

QQ|手机版|小黑屋|Lazarus中国|Lazarus中文社区 ( 鄂ICP备16006501号-1 )

GMT+8, 2025-5-2 20:21 , Processed in 0.028289 second(s), 10 queries , Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表