如何在 Windows PC 上实现键盘自动重复? [英] How is keyboard auto-repeat implemented on a Windows PC?

查看:15
本文介绍了如何在 Windows PC 上实现键盘自动重复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在 Windows 上拦截(并对其进行任意处理)自动重复按键.我想知道键盘自动重复是如何实现的,以便我知道我有哪些选项.即我可以在以下位置拦截:

I want to be able to intercept (and do arbitrary processing on) auto-repeating key presses on Windows. I'd like to know how keyboard auto-repeat is implemented so that I know what options I have. i.e. can I intercept at the:

  • 应用,
  • 设备驱动程序和/或
  • 硬件级别

?

更新:看起来自动重复(很糟糕?)在硬件级别生成,然后被设备驱动程序覆盖(看这里).

Update: It looks like auto-repeat is (poorly?) generated at the hardware level and then overridden by device drivers (see here).

推荐答案

要修改或过滤行为,您可以使用钩子拦截键:

To modify or filter behavior, you can intercept keys using a hook:

SetWindowsHookEx 使用 WH_KEYBOARD

挂钩程序接收,其中其他,重复计数(由于按住键)

The hook procedure receives, among others, the repeat count (due to holding down the key)

请注意,低级键盘挂钩 (WH_KEYBOARD_LL) 不接收重复计数.

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

如果您的所有窗口都在同一个 trhead 中创建,您可以使用特定于线程的钩子,并避免将钩子过程移动到 DLL.

If all your windows are created in the same trhead, you can use a thread-specific hook, and avoid moving the hook procedure to a DLL.

我依稀记得重复计数是由键盘本身生成的,并且 LL 挂钩会发送重复的 keydown 事件——不过我可能弄错了.在 DOS 下,在 BIOS 中或通过 BIOS 调用设置的键重复率和时间在拔下和重新插入 DIN 或 PS/2 键盘时确实返回到默认值.我不确定为什么你需要确切地知道.

I dimly remember that repeat counts are generated by the keyboard itself and the LL hook sends repeated keydown events - I may be mistaken, though. Under DOS, the key repeat rate and time that was set in BIOS or through a BIOS call did return to default values when a DIN or PS/2 keyboard was unplugged and replugged. I am not sure WHY you need to know exactly.

这篇关于如何在 Windows PC 上实现键盘自动重复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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