Skip to content

Instantly share code, notes, and snippets.

@PierrePaul PierrePaul/pedals.py
Last active Oct 12, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.