Last active
March 21, 2018 06:20
-
-
Save zacharied/9428b8894b89e9214e36d87fa58b0427 to your computer and use it in GitHub Desktop.
Bind foot pedal signals to certain keys. Could be replaced by modifying the udev database to reinterpret the foot pedal as a keyboard.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Script for binding my foot pedal. | |
import sys, os, glob | |
import evdev | |
from evdev import ecodes | |
# Search system devices for a pedal. | |
devices = glob.glob('/dev/input/by-id/usb-VEC_VEC_USB_Footpedal-event-*') | |
if len(devices) == 0: | |
print("No pedals found.", file=sys.stderr) | |
sys.exit(1) | |
elif len(devices) > 1: | |
print("More than one pedal found.", file=sys.stderr) | |
print("Using device '{}'.".format(devices[0])) | |
pedal = '/dev/input/by-id/' + os.readlink(devices[0]) | |
device = evdev.InputDevice(pedal) | |
ui = evdev.uinput.UInput() | |
for event in device.read_loop(): | |
if event.code == 256: | |
if event.value == 1: | |
ui.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_BACKSLASH, 1) | |
ui.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_BACKSLASH, 0) | |
ui.syn() | |
if event.code == 257: | |
if event.value == 1: | |
ui.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_ESC, 1) | |
ui.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_ESC, 0) | |
ui.syn() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment