V
V
Vitaly Gerasimov2015-09-14 08:45:40
Python
Vitaly Gerasimov, 2015-09-14 08:45:40

How to catch the device (usb) without using third-party libraries?

Good day.
Can you please tell me how to catch button presses without using third-party libraries?
Empirically, I found that referring to


file = open('/dev/input/event4', 'rb')
while True:
for rs in file.read(1):
print(rs)

I can get something, but how do I decode the output?
so that everything is displayed in a more understandable form
Thank you in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Gerasimov, 2015-09-15
@JokerOfGod

If anyone is interested, I found an option how to catch the pressed button, no matter where, the main thing is that the script be launched
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()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question