<small id='HaoQd'></small><noframes id='HaoQd'>

  • <tfoot id='HaoQd'></tfoot>

        <bdo id='HaoQd'></bdo><ul id='HaoQd'></ul>
      <i id='HaoQd'><tr id='HaoQd'><dt id='HaoQd'><q id='HaoQd'><span id='HaoQd'><b id='HaoQd'><form id='HaoQd'><ins id='HaoQd'></ins><ul id='HaoQd'></ul><sub id='HaoQd'></sub></form><legend id='HaoQd'></legend><bdo id='HaoQd'><pre id='HaoQd'><center id='HaoQd'></center></pre></bdo></b><th id='HaoQd'></th></span></q></dt></tr></i><div id='HaoQd'><tfoot id='HaoQd'></tfoot><dl id='HaoQd'><fieldset id='HaoQd'></fieldset></dl></div>
      1. <legend id='HaoQd'><style id='HaoQd'><dir id='HaoQd'><q id='HaoQd'></q></dir></style></legend>

      2. SetWindowsHookEx 全局键盘挂钩未捕获所有按键

        SetWindowsHookEx global keyboard hook not catching all keypresses(SetWindowsHookEx 全局键盘挂钩未捕获所有按键)
            1. <legend id='ZW0PE'><style id='ZW0PE'><dir id='ZW0PE'><q id='ZW0PE'></q></dir></style></legend>

              <tfoot id='ZW0PE'></tfoot>

              <small id='ZW0PE'></small><noframes id='ZW0PE'>

                <tbody id='ZW0PE'></tbody>
              <i id='ZW0PE'><tr id='ZW0PE'><dt id='ZW0PE'><q id='ZW0PE'><span id='ZW0PE'><b id='ZW0PE'><form id='ZW0PE'><ins id='ZW0PE'></ins><ul id='ZW0PE'></ul><sub id='ZW0PE'></sub></form><legend id='ZW0PE'></legend><bdo id='ZW0PE'><pre id='ZW0PE'><center id='ZW0PE'></center></pre></bdo></b><th id='ZW0PE'></th></span></q></dt></tr></i><div id='ZW0PE'><tfoot id='ZW0PE'></tfoot><dl id='ZW0PE'><fieldset id='ZW0PE'></fieldset></dl></div>
                  <bdo id='ZW0PE'></bdo><ul id='ZW0PE'></ul>
                  本文介绍了SetWindowsHookEx 全局键盘挂钩未捕获所有按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在编写属于自动化系统一部分的代码.我想添加一个键盘钩子来提前结束测试,我通过使用 SetWindowHookEx 来做到这一点.

                  I'm writing code that is part of an automation system. I wanted to add a keyboard hook to end the test prematurely, and I did this by using SetWindowHookEx.

                  我的代码看起来很像这样:http://support.microsoft.com/kb/318804

                  My code looks pretty much like this: http://support.microsoft.com/kb/318804

                  这是我的 SetWindowsHookEx 调用:

                  Here's my SetWindowsHookEx call:

                  hHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProcedure, GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);
                  

                  现在,当我运行自动化时,自动化系统内的按键(来自 SendKeys)会触发键盘挂钩方法,但是当我手动敲击键盘时它不会被触发.

                  Now, when I run my automation, keypresses from within the automation system (from SendKeys) trigger the keyboard hook method, but when I hit the keyboard manually it isn't triggered.

                  如果有帮助,我可以分享更多代码,但它是更大系统的一部分.我很确定:

                  I can share more code if that helps, but it's part of a much larger system. I'm pretty sure that either:

                  1. 我的 SetWindowsHookEx 不正确,或者
                  2. 自动化系统中的某些东西绕过了我的键盘钩子(不过我真的不知道如何分辨).
                  1. My SetWindowsHookEx isn't correct, or
                  2. Something in the automation system is bypassing my keyboard hook (I don't really know how to tell though).

                  我编写了一个测试应用程序,该应用程序使用来自 microsoft.com 的示例代码来确定我的方法具有优点(即它有效),但我无法将它与自动化系统集成.

                  I've written a test application that uses the sample code from microsoft.com to determine that my approach has merit (i.e., it works), but I'm having trouble integrating it with the automation system.

                  任何关于如何确定哪里出了问题的想法都将不胜感激.

                  Any thoughts on how to determine where things are going wrong would be greatly appreciated.

                  自动化工具中没有其他 SetWindowsHookEx 实例.我不太清楚全局键盘挂钩 w.r.t 的细微差别.线程和桌面.如果我添加一个全局键盘钩子,它的添加位置是否重要?

                  There are no other instances of SetWindowsHookEx in the automation harness. I'm not too clear the nuances of global keyboard hooks w.r.t. threads and the desktop. If I add a global keyboard hook, should it matter from where it was added?

                  推荐答案

                  回复你的评论-

                  如果您只需要测试某个键是否已关闭以退出测试,您只需轮询 GetAsyncKeyState(),这将告诉您某个特定的键是否已关闭,无论是谁当前具有键盘焦点.

                  If you just need to test whether a key is down in order to exit your test, you could just poll on GetAsyncKeyState(), this will tell you if a particular key is down regardless of who currently has keyboard focus.

                  您的用户必须按住一个键或一组键足够长的时间才能让您的轮询注意到,这意味着他们按住它几秒钟,或者您必须更频繁地轮询一秒钟.

                  You user would have to hold a key or set of keys down long enough for your polling to notice, which means either they hold it down for a few seconds, or you have to poll more frequently than a second.

                  但这比全局键盘钩子要少得多.

                  But that would be a lot less intrusive than a global keyboard hook.

                  全局挂钩可能会序列化通常彼此异步的内核部分,因此它们也会损害系统性能.

                  Global hooks supposedly serialize parts of the kernel that normally would be async from each other, so they also harm system performance.

                  这篇关于SetWindowsHookEx 全局键盘挂钩未捕获所有按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  How can I force the PropertyGrid to show a custom dialog for a specific property?(如何强制 PropertyGrid 显示特定属性的自定义对话框?)
                  Associate attribute with code generated property in .net(将属性与 .net 中的代码生成属性相关联)
                    <bdo id='1rkHw'></bdo><ul id='1rkHw'></ul>

                    <small id='1rkHw'></small><noframes id='1rkHw'>

                    <legend id='1rkHw'><style id='1rkHw'><dir id='1rkHw'><q id='1rkHw'></q></dir></style></legend>

                        <tbody id='1rkHw'></tbody>
                        <i id='1rkHw'><tr id='1rkHw'><dt id='1rkHw'><q id='1rkHw'><span id='1rkHw'><b id='1rkHw'><form id='1rkHw'><ins id='1rkHw'></ins><ul id='1rkHw'></ul><sub id='1rkHw'></sub></form><legend id='1rkHw'></legend><bdo id='1rkHw'><pre id='1rkHw'><center id='1rkHw'></center></pre></bdo></b><th id='1rkHw'></th></span></q></dt></tr></i><div id='1rkHw'><tfoot id='1rkHw'></tfoot><dl id='1rkHw'><fieldset id='1rkHw'></fieldset></dl></div>
                          <tfoot id='1rkHw'></tfoot>