Skip to content

Instantly share code, notes, and snippets.

@PierrePaul
Last active October 12, 2017 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PierrePaul/6a295ed4553e27399462f047be8d499a to your computer and use it in GitHub Desktop.
Save PierrePaul/6a295ed4553e27399462f047be8d499a to your computer and use it in GitHub Desktop.
pedals analog input to keystroke
#!/usr/bin/python3
import evdev
from pykeyboard import PyKeyboard
device = evdev.InputDevice('/dev/input/event2')
k = PyKeyboard()
pressing_alt = False
pressing_ctrl = False
pressing_super = False
for event in device.read_loop():
if event.code != 0 and event.value != 0:
pass
#print(event)
if event.code == 2 and event.value < 200 and pressing_alt is False:
k.press_key(k.alt_key)
pressing_alt = True
if event.code == 2 and event.value > 200 and pressing_alt is True:
k.release_key(k.alt_key)
pressing_alt = False
if event.code == 5 and event.value < 200 and pressing_super is False:
k.press_key(k.super_l_key)
pressing_super = True
if event.code == 5 and event.value > 200 and pressing_super is True:
k.release_key(k.super_l_key)
pressing_super = False
if event.code == 1 and event.value < 200 and pressing_ctrl is False:
k.press_key(k.control_key)
pressing_ctrl = True
if event.code == 1 and event.value > 200 and pressing_ctrl is True:
k.release_key(k.control_key)
pressing_ctrl = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment