Answer the question
In order to leave comments, you need to log in
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)
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question