来自线程的 WH_MOUSE_LL 上的 SetWindowsHookEx 问题 - 冻结 5 秒且没有触发 [英] Issues with SetWindowsHookEx on WH_MOUSE_LL from thread - freezes for 5 sec and no trigger

查看:22
本文介绍了来自线程的 WH_MOUSE_LL 上的 SetWindowsHookEx 问题 - 冻结 5 秒且没有触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用产生一个线程,在这个线程中我执行以下代码:

My app spawns a thread, in this thread i do the following code:

function myLLMouseHook_js(nCode, wParam, lParam) {

    var rez_CallNext = CallNextHookEx(null, nCode, wParam, lParam);
    console.info('rez_CallNext:', rez_CallNext, rez_CallNext.toString());

    return rez_CallNext;
};

aHhk = SetWindowsHookEx(WH_MOUSE_LL, myLLMouseHook_c, null, 0);

它注册正确,但是在 5 秒钟内它冻结了我的鼠标,它不移动或什么也不移动(此时键盘输入有效).回调永远不会被触发.如果我尝试在 aHhk 上脱钩,它会返回 true.这太奇怪了.该线程处于活动状态并正在运行.

It registers properly, however for 5 seconds it freezes my mouse, it doesnt move or nothing (keyboard input works at this time). Callback is never fired. If I attempt unhook on aHhk it returns true. It's so odd. The thread is alive and running.

如果我从主线程运行相同的代码,它可以完美运行.有人有什么想法吗?

If I run this same code from main thread it works flawlessly. Does anyone hvae any ideas?

请原谅最近在这方面的许多问题,我正在努力解决通过多个(同步/阻塞,异步/事件副本)监视鼠标的一个目标,因此不可阻塞[原始输入 api 方法由于无法访问WndProc]) 在教程中编写的方法.

Forgive the many issues on this lately, im working on solving one goal of monitoring mouse via multiple (sync/blocking, async/copy of events so non-blockable[the raw input api method was giving probs due to no access to WndProc]) methods to write in tutorials.

推荐答案

可能的解释是线程没有运行消息循环.正如记录,低级钩子需要钩子的拥有线程运行消息循环.

Likely explanation is that the thread is not running a message loop. As documented, low level hooks need the hook's owning thread to run a message loop.

这个钩子在安装它的线程的上下文中被调用.通过向安装钩子的线程发送消息来进行调用.因此,安装钩子的线程必须有一个消息循环.

This hook is called in the context of the thread that installed it. The call is made by sending a message to the thread that installed the hook. Therefore, the thread that installed the hook must have a message loop.

这篇关于来自线程的 WH_MOUSE_LL 上的 SetWindowsHookEx 问题 - 冻结 5 秒且没有触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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