【发布时间】:2016-06-02 06:12:16
【问题描述】:
我想使用 Python 检测何时按下键盘上的 XF86Launch1 键。
我有一个带有蓝牙连接键盘的无头服务器。每当按下特定的多媒体键时,我想启动一个命令行程序。
目前,我正在使用:
import sys
import tty, termios
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(fd)
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
print getch()
但它不会检测多媒体键。当我按下它们时,什么也没有打印出来。
有没有办法在无头 Ubuntu 机器上检测这些键 - 或者是在按键上启动程序的更好方法?
【问题讨论】:
标签: python keyboard keyboard-shortcuts key-bindings