With this simple Python script we will detect keypresses.
If you don't have pynput module, just type this in cmd: "pip install pynput".
We need two custom functions, press_on() will be activated when you press buttons, and press_off() will be activated on release.
If we press Escape, script will terminate.
This is just simple printing on screen, but you can upgrade your functions to do many other things.
from pynput.keyboard import *
def press_on(key):
print('Press ON {}'.format(key))
def press_off(key):
print('Press OFF: {}'.format(key))
if key == Key.esc:
return False
with Listener(on_press = press_on, on_release = press_off) as listener:
listener.join()
Learn More:
Free Python Programming Course
Python Examples
Python How To
Python Modules
No comments:
Post a Comment