Windows Mobile 5或更高版本(智能手机平台)中的全局键盘挂钩如何? [英] global keyboard hook in windows mobile 5 or above (smartphone platform), how?

查看:78
本文介绍了Windows Mobile 5或更高版本(智能手机平台)中的全局键盘挂钩如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我想我必须在c ++中做到这一点,有人知道这个问题吗?我已经在各处搜索,并且发现了一些有关Windows CE上的键盘挂钩的文章,Windows Mobile是Windows CE,不是吗? 另一个问题:我可以使用哪种免费编译器(适用于Windows Mobile的ide)?

so, i guess i must do it in c++, anyone know about this problem? i already searching everywhere and i found some articles about keyboard hook on windows ce, windows mobile is windows ce, isn't it? another questions: which free compiler, ide for windows mobile i could use?

推荐答案

SetWindowsHookEx在任何WindowsCE(读取:移动)版本上均不受支持.实际上,实际上不支持钩子.

SetWindowsHookEx is not supported on any WindowsCE (read: Mobile) version. Hooks in general are not supported, in fact.

但是,如果您愿意使用无文档/不受支持的API,则可以退出 SetWindowsHookEx ,然后像在正常Windows上一样调用它.您需要WH_KEYBOARD_LL,有点谷歌搜索说是20.

However, if you're willing to use undocument/unsupported APIs you can pull SetWindowsHookEx out of coredll.dll, and call it as you would on proper Windows. You want WH_KEYBOARD_LL, which a little googling says is 20.

实际上,您将需要提取指向以下方法的指针: UnhookWindowsHookEx .

You'll actually need to pull out pointers to the following methods: SetWindowsHookEx, CallNextHookEx, and UnhookWindowsHookEx.

您的代码将类似于(未经测试):

Your code will resemble (this is untested):

//myHook.dll
LRESULT myLowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
  //You'll need to pull a reference to CallNextHookEx out of coredll as well
  if(nCode < 0) return CallNextHookEx(nCode, wParam, lParam);

  KBDLLHOOKSTRUCT data = *((PKBDLLHOOKSTRUCT)lParam);

  //Do something with data

  return CallNextHookEx(nCode, wParam, lParam);
}

//Main Code, which ignores all the nasty function pointers you'd ACTUALLY have to use to do this
...
HHOOK hook = SetWindowsHookEx(WH_KEYBOARD_LL, pMyLowLevelKeyboardProc, hMyHookDll, 0);
...
//Some point in the future
UnhookWindowsHookEx(hook);

但是我强烈建议不要这样做.我非常怀疑此代码能否在Windows Mobile的所有将来版本中正常使用.考虑使用其他方法来实现您实际上想要的目标.

I would strongly suggest against this however. I doubt very much that this code will keep working for all future versions of Windows Mobile. Consider some other way to achieve whatever it is you're actually after.

我不能说我对免费编译器或IDE有任何建议.除了Visual Studio for C/C ++之外,其他任何事情都会使我感到沮丧.我认为这比起对其他工具的评论更能反映我的习惯.

I can't say I have any recommendations for free compilers or IDEs. Anything other than Visual Studio for C/C++ always causes me a lot of frustration. I think this is more a reflection of my habits than a commentary on any other tools.

这篇关于Windows Mobile 5或更高版本(智能手机平台)中的全局键盘挂钩如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆