求助 Python 监听大写锁定键
資深大佬 : JackalZhao 6
需求:
持续监听大写锁定键,当按下后,保持按下状态超过 0.5 秒时,立即 print(‘超过 0.5 秒’)
(一旦在持续 0.5 秒之前松开了,那就啥都不做)
当按下超过 0.5 秒后,松开这个按键时,print(‘松开了’)。
尽可能简洁、占用资源尽可能少。
大佬有話說 (10)
需求:
持续监听大写锁定键,当按下后,保持按下状态超过 0.5 秒时,立即 print(‘超过 0.5 秒’)
(一旦在持续 0.5 秒之前松开了,那就啥都不做)
当按下超过 0.5 秒后,松开这个按键时,print(‘松开了’)。
尽可能简洁、占用资源尽可能少。
给 LZ 两个关键词
SetWindowsHookEx
和
WH_KEYBOARD_LL
自己搜去吧
The Old New Thing 里面也有一篇文章提到了这个:
https://devblogs.microsoft.com/oldnewthing/20050425-41/?p=35803
The WH_KEYBOARD_LL and WH_MOUSE_LL hooks are exceptions to this rule. These two are non-injecting hooks, as explained in their respective documentation pages. Rather, the hook function is called in its original thread context.