.NET 和 Delphi 中的多个键盘挂钩

发布于 2024-09-16 14:01:58 字数 232 浏览 3 评论 0原文

我有一个包含 .NET 和 Delphi 组件的应用程序 我在两个组件中注册了键盘钩子(使用 SetWindowsHookEx)。 我首先在.NET 中注册,然后在Delphi 中注册。

问题是,Delphi 中的钩子委托在 .NET 中的钩子委托之前被调用。

根据 MSDN,钩子链只是一个列表,据我了解,应该根据注册顺序。

有人知道这里发生了什么事吗? 提前致谢!

I have an application with both .NET and Delphi components
I register to a keyboard hook (with SetWindowsHookEx) in both components.
I first register in .NET, and later in Delphi.

The problem is, the hook delegate in Delphi is called before the hook delegate in .NET.

According to MSDN, the hook chain is just a list, and as I understand the delegates should be called according to the order of registration.

Anyone has an idea what is going on here?
Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浮萍、无处依 2024-09-23 14:01:58

你误会了。 MSDN 中的钩子概述是这样描述的(强调是添加的):

SetWindowsHookEx 函数始终安装挂钩过程在钩链的开头。当特定类型的钩子监视的事件发生时,系统调用与该钩子关联的钩子链开头的过程。链中的每个钩子过程确定是否将事件传递给下一个过程。挂钩过程通过调用 CallNextHookEx 将事件传递给下一个过程功能。


因此,如果您的 Delphi 钩子最后安装并且最先调用,这正是预期的行为。根本没有什么“发生”。

You've misunderstood. The hook overview in MSDN describes it like this (emphasis added):

The SetWindowsHookEx function always installs a hook procedure at the beginning of a hook chain. When an event occurs that is monitored by a particular type of hook, the system calls the procedure at the beginning of the hook chain associated with the hook. Each hook procedure in the chain determines whether to pass the event to the next procedure. A hook procedure passes an event to the next procedure by calling the CallNextHookEx function.

Therefore, it's precisely the expected behavior if your Delphi hook is installed last and is called first. There's nothing "going on" at all.

感受沵的脚步 2024-09-23 14:01:58

钩子列表不是列表,而是链。新安装的钩子保留对前一个钩子的引用。这意味着后来安装的钩子总是在先安装的钩子之前执行。

The hook list is not a list, but a chain. Newly installed hook keeps the reference to the previous one. This means that the hook, installed later, is always executed before the hook installed earlier.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文