鍵盤控制
-
在終端機中執行以下指令:
pip3 install pynput
from pynput.keyboard import Key from pynput.keyboard import Listener def on_press(key): print('{0} pressed'.format(key)) def on_release(key): print('{0} release'.format(key)) if key == Key.esc: # Stop listener return False # Collect events until released with Listener( on_press=on_press, on_release=on_release) as listener: listener.join()
-