pip install keyboard
import keyboard def hello(): print("hello world") # 右键触发hello函数 keyboard.add_hotkey('right', hello) # 阻塞,直至等待到ctrl+c信号 keyboard.wait('ctrl + c')