低级钩子/SetWindowsHookEx lParam 自动重复? [英] Low Level Hook / SetWindowsHookEx lParam Auto-Repeat?

查看:37
本文介绍了低级钩子/SetWindowsHookEx lParam 自动重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里阅读:键盘如何自动-在 Windows PC 上重复实现?

我知道低级键盘钩子不接收自动重复计数:/

I understand that low level keyboard hook does't receive auto-repeat count :/

注意低级键盘钩子(WH_KEYBOARD_LL)没有接收重复计数.

Note that the low level keyboard hook (WH_KEYBOARD_LL) does not receive the repeat count.

但是为什么??o.O

我过去使用 Windows 消息提取自动重复计数的方式:
int repeatCount = (lParam & KF_REPEAT);

The way I used to extract the auto-repeat count using windows messages:
int repeatCount = (lParam & KF_REPEAT);

但是当我使用 SetWindowsHookEx 挂钩 WH_KEYBOARD_LL 时,由于某种原因它不起作用.

But it doesn't work for some reason when I use the SetWindowsHookEx hooking the WH_KEYBOARD_LL.

我想在使用全局钩子时过滤 Space 键的自动重复.有没有办法做到这一点?可能是一种确定按键按下是否自动重复(即按住)的创造性方法?

I want to filter auto-repeat for the Space key while using the global hook. Is there a way doing that? Possibly a creative way to determine if the key down press is auto-repeated(i.e held down)?

示例代码:

    if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)
    {
        KBDLLHOOKSTRUCT kbd = *(KBDLLHOOKSTRUCT *)(lParam);
        if (kbd.vkCode == VK_SPACE && !(lParam & KF_REPEAT))
        {
            // do something
        }
    }

推荐答案

我知道低级键盘钩子不接收自动重复计数......但为什么??

I understand that low level keyboard hook does't receive auto-repeat count ... But why??

因为自动重复计数器在低级别不存在.在那个级别,您从键盘本身获取事件.按下键,按下键,就是这样.键盘不受计数器控制.

Because the auto-repeat counter simply does not exist at the low level. At that level, you are getting events from the keyboard itself. Key down, key up, that is it. The keyboard is not in control of the counter.

更高级别,当系统处理来自键盘的那些低级事件并生成分发给应用程序的关键消息时,系统会运行自己的计时器来管理重复计数器并创建每当计数器增加时对应的关键消息.

At a higher level, when the system is processing those low level events from the keyboard and generating key messages for distribution to apps, the system runs its own timer to manage the repeat counter and create the corresponding key messages whenever the counter is incremented.

我想在使用全局钩子时过滤 Space 键的自动重复.有没有办法做到这一点?

I want to filter auto-repeat for the Space key while using the global hook. Is there a way doing that?

低级钩子中,您必须像系统一样运行自己的计时器.

In a low level hook, you will have to run your own timer, just like the system does.

否则,使用更高级别的消息钩子而不是键盘钩子.

Otherwise, use a higher level message hook instead of a keyboard hook.

这篇关于低级钩子/SetWindowsHookEx lParam 自动重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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