Python模块(键盘)无法识别"fn"键 [英] Python module (keyboard) is not recognizing 'fn' key
问题描述
我想将功能键用作python(3.6)的键盘快捷键的一部分,但无法识别fn键事件.
I want to use the function keys as a part of a keyboard shortcut with python (3.6) and it is failing to recognize the fn key event.
import keyboard
keyboard.press_and_release('fn+down')
推荐答案
keyboard
项目不支持fn
键,否. keyboard.all_modifiers
集向您显示了它可以支持的内容.
The keyboard
project doesn't support the fn
key, no. The keyboard.all_modifiers
set shows you what it can support.
在产生以下内容的Mac上:
On my Mac that produces:
>>> import keyboard
>>> keyboard.all_modifiers
{'alt', 'ctrl', 'windows', 'shift'}
考虑到Fn
键可能对操作系统不可见.来自维基百科:
Fn键是一种元修饰符键,因为当按下键盘上的其他键时,它将导致操作系统看到更改的扫描代码.这使键盘可以直接模拟全尺寸键盘,因此操作系统可以使用为全尺寸键盘设计的标准键盘映射. 但是,由于操作系统没有Fn键的概念,因此与所有其他标准键盘键不同,该键通常无法在软件中重新映射.
(强调粗体的人).
Apple Macs除外,我可以肯定地确定Windows并非如此.
Apple Macs are the exception to this, I'm reasonably sure Windows is not.
对Mac的支持仍处于试验阶段,根据项目描述:
Mac support is still experimental, from the project description:
可与Windows和Linux配合使用(需要sudo),具有实验性的OS X支持(感谢@glitchassassin!).
(强调粗体的人).
该项目已经存在一个未解决的问题(#221,无法检测到在Mac键盘上作为功能键的第一行按键 )对此进行跟踪.
There already is an open issue with the project (#221, Unable to detect the top row of keys on Mac keyboard as function keys) tracking this.
对于Windows和Linux,请尝试捕获fn+down
实际转换为操作系统的键代码(使用 keyboard.hook()
回调,请参见此示例),然后执行该键控代码.
For Windows and Linux, try to capture the keycode that fn+down
actually translates to for the OS (with a keyboard.hook()
callback, see this example), then execute that keycode.
如果fn
+ down
控制您的音量,只需使用"volume down"
或整数值0xae
作为扫描代码:
If fn
+down
controls your volume, just use "volume down"
or integer value 0xae
as the scan code:
keyboard.send(0xae)
这篇关于Python模块(键盘)无法识别"fn"键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!