Skip to content

Instantly share code, notes, and snippets.

@gicmo
Created February 24, 2017 16:09
Show Gist options
  • Save gicmo/fa108c5439ceb3b56e20aab21a21e2e3 to your computer and use it in GitHub Desktop.
Save gicmo/fa108c5439ceb3b56e20aab21a21e2e3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from evdev import InputDevice, categorize, ecodes, list_devices
import argparse
def main():
parser = argparse.ArgumentParser(description="little evdev helper")
parser.add_argument("device", help='input device to open', default=None, nargs='?')
args = parser.parse_args()
devstr = args.device
if devstr is None:
devices = map(InputDevice, list_devices())
for device in devices:
print(device.fn, device.name, device.phys)
return
if devstr.startswith('event'):
devstr = '/dev/input/' + devstr
device = InputDevice(devstr)
print(device)
for event in device.read_loop():
if event.type == ecodes.EV_KEY:
print(categorize(event))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment