0

所以,我想我必须用 C++ 来做,有人知道这个问题吗?我已经到处搜索了,我发现了一些关于 windows ce 上的键盘挂钩的文章,windows mobile 是 windows ce,不是吗?另一个问题:我可以使用哪个免费的编译器,适用于 windows mobile 的 ide?

4

2 回答 2

1

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

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.

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);

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.

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.

于 2009-06-26T07:36:55.407 回答
0

http://www.naresh.se/2009/09/08/getkeyboardstate-mousehooks-not-available-in-windows-mobile/

按照上面的网址。它具有在 Windows Mobile 和 Windows CE 上工作所需的代码,并且还有一个很好的解释以及一个论坛,可以进一步讨论......

忘了说代码是 C# 中的一些其他用户的要求......

于 2009-09-09T07:33:53.817 回答