Created
May 7, 2015 18:55
-
-
Save mike10004/3aa7640e8a0f6031ca8c 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 | |
# inspired by http://stackoverflow.com/questions/5060710/format-of-dev-input-event | |
import struct | |
from argparse import ArgumentParser | |
if __name__ == '__main__': | |
p = ArgumentParser() | |
p.description = 'Read events from /dev/input and print them to console. Must be run as root.' | |
p.add_argument("--source", default="/dev/input/event0", help="specify source (entry in /dev/input/*; default is event0)") | |
args = p.parse_args() | |
with open(args.source, 'r') as source: | |
index = 0 | |
event_format = "llHHI" | |
event_len = struct.calcsize(event_format) | |
event = source.read(event_len) | |
while event: | |
(tv_sec, tv_usec, evt_type, code, value) = struct.unpack(event_format, event) | |
print "%4d %8u %8u %8u" % (index, evt_type, code, value) | |
index += 1 | |
event = source.read(event_len) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment