Created
February 24, 2017 16:09
-
-
Save gicmo/fa108c5439ceb3b56e20aab21a21e2e3 to your computer and use it in GitHub Desktop.
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 | |
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