Skip to content

Instantly share code, notes, and snippets.

@magemore
Created November 25, 2019 23:30
Show Gist options
  • Save magemore/dcda10c7f19f0f47d736b3fbf6309cf6 to your computer and use it in GitHub Desktop.
Save magemore/dcda10c7f19f0f47d736b3fbf6309cf6 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import struct
import time
import sys
infile_path = "/dev/input/event6"
#long int, long int, unsigned short, unsigned short, unsigned int
FORMAT = 'llHHI'
EVENT_SIZE = struct.calcsize(FORMAT)
#open file in binary mode
in_file = open(infile_path, "rb")
event = in_file.read(EVENT_SIZE)
while event:
(tv_sec, tv_usec, type, code, value) = struct.unpack(FORMAT, event)
if type != 0 or code != 0 or value != 0:
print("Event type %u, code %u, value %u at %d.%d" % \
(type, code, value, tv_sec, tv_usec))
if value == 1:
print("G1")
if value == 2:
print("G2")
else:
# Events with code, type and value == 0 are "separator" events
print("===========================================")
event = in_file.read(EVENT_SIZE)
in_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment