简体   繁体   English

如何要求键盘挂钩处理父窗口后的消息

[英]How to ask keyboard hook to process messages AFTER the parent window

The title says it all. 标题说明了一切。 How can I ask my keyboard hook to tackle incoming keyboard message AFTER the parent window has processed them? 在父窗口处理它们后,如何要求键盘挂钩处理传入的键盘消息? Reading the docs I found there is a value named WH_CALLWNDPROCRET that does exactly this, but I need to specify WH_KEYBOARD there (to make it a keyboard hook of course), and the value doesn't appear to be a bit flag, so I can't combine both. 阅读文档后,我发现确实有一个名为WH_CALLWNDPROCRET的值可以执行此操作,但是我需要在WH_KEYBOARD指定WH_KEYBOARD (当然要使其成为键盘钩子),并且该值似乎不是位标志,因此我可以不能两者兼而有之。

Background : I'm writing an add-in for Word 2013, which needs to monitor certain keys and take appropriate action only after Word has finished processing those keys. 背景 :我正在为Word 2013编写一个加载项,该加载项需要监视某些键并仅 Word完成处理这些键之后才采取适当的措施。 I'm using globalmousekeyhook project for hooking. 我正在使用globalmousekeyhook项目进行挂钩。

The library you are referring to is subscribing to following four hooks: 您所引用的库正在订阅以下四个钩子:

  • WH_KEYBOARD_LL WH_KEYBOARD_LL
  • WH_KEYBOARD WH_KEYBOARD
  • WH_MOUSE_LL WH_MOUSE_LL
  • WH_MOUSE WH_MOUSE

When you subscribe to a hook you give a system a callback to your code, which will be executed according to the rules which differ from hook type to hook type. 当您订阅一个钩子时,您会给系统一个代码回调,该回调将根据不同钩子类型的规则执行。 Also the information the callback will deliver to you must be interpreted differently. 同样,回调将提供给您的信息也必须以不同的方式解释。 These 4 deliver information about mouse positions, key strokes etc. 这4个控件提供有关鼠标位置,按键等的信息。

There are many different types of hooks you can subscribe to. 您可以订阅很多不同类型的钩子。 See: Hook Overview 请参阅: 挂钩概述

The WH_CALLWNDPROCRET yo are referring to is one of them. 您所指的WH_CALLWNDPROCRET是其中之一。 It has different callback invocation behavior and delivers you all messages sent to window. 它具有不同的回调调用行为,并向您传递所有发送到窗口的消息。 These may include theoretically any of hundreds of possible messages, not only keyboard and mouse messages. 从理论上讲,这些消息可能包括数百种可能的消息中的任何一种,而不仅仅是键盘和鼠标消息。

To answer your question the library globalmousekeyhook can not subscribe to any other hooks than those 4 mentioned above. 为了回答您的问题,库globalmousekeyhook除了上述4个钩子之外,不能订阅任何其他钩子。

Good news is that you can probably reuse code form the library to implement your own subscription. 好消息是您可以重用库中的代码来实现自己的订阅。

  • You can reuse code to install the hook. 您可以重复使用代码来安装挂钩。
  • The signature of your callback will of course be different. 回调的签名当然会有所不同。
  • Then you will get all messages. 然后,您将收到所有消息。
  • Filter out only those messages you are interested in eg WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, WM_SYSKEYUP . 仅过滤出您感兴趣的消息,例如WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, WM_SYSKEYUP
  • Interpret the data delivered along with messages. 解释与消息一起传递的数据。 Also here you can reuse some code from the library. 同样在这里,您可以重用库中的一些代码。

Conclusion No, the library can not do what you are looking for. 结论不,图书馆无法满足您的需求。 Yes, you can probably achieve that by reusing code from that library. 是的,您可能可以通过重用该库中的代码来实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM