Skip to content

Instantly share code, notes, and snippets.

@t184256
Last active January 17, 2018 16:20
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 t184256/3234302966f64a0c9095c663cdc616cb to your computer and use it in GitHub Desktop.
Save t184256/3234302966f64a0c9095c663cdc616cb to your computer and use it in GitHub Desktop.
example of evdev/uinput based remapping, probably not the best one
import os
import atexit
import uinput
import evdev
#os.system('sudo modprobe uinput')
MAPPING = {
evdev.ecodes.KEY_A: uinput.KEY_ESC,
evdev.ecodes.KEY_B: uinput.KEY_END,
evdev.ecodes.KEY_C: uinput.KEY_ENTER,
}
device = uinput.Device(MAPPING.values(), name='Pedal keys')
PATH = '/dev/input/by-id/usb-PCsensor_FootSwitch3-F1.8-event-mouse'
in_dev = evdev.InputDevice(PATH)
atexit.register(in_dev.ungrab)
in_dev.grab()
for event in in_dev.read_loop():
if event.type == evdev.ecodes.EV_KEY:
device.emit(MAPPING[event.code], event.value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment