使用pynput监听键盘组合键
from pynput.keyboard import Key, Controller,Listenerkeyboard = Controller()def on_press(key):print('{0} 被按下'.format(key)) def on_release(key):print('{0} 被释放'.format(key))if key == Key.esc:return Falseif str(key) == r"<48>":# ctrl 0test()def test():print ('按下ctrl 0,运行测试程序')# 创建监听with Listener(on_press=on_press,on_release=on_release) as listener:listener.join()