import struct
file = open('/dev/input/event4', 'rb')
FORMAT = 'llHHI'
EVENT_SIZE = struct.calcsize(FORMAT)
event = file.read(EVENT_SIZE)
while event:
code = struct.unpack(FORMAT, event)
if code[3] != 0:
print("Event code: "+str(code[3]))
event = file.read(EVENT_SIZE)
file.close()