Mit einer umgebauten Maus will ich den Raspberry PI als Radio steuern. Die Maus soll dabei direct abgegriffen werden. Hier ein paar Codeschnipsel wie das geht:
#!/usr/bin/python
import struct
import time
import sys
import select
infile_path = "/dev/input/event" + (sys.argv[1] if len(sys.argv) > 1 else "0")
#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 == 1 and code==273 and value==1:
print("Key Rechts")
if type == 1 and code==272 and value==1:
print("Key links")
if type == 1 and code==274 and value==1:
print("RadKlick");
if type == 2 and code==8 and value ==1:
# swallow identical events directly after the existing one
while (in_file in select.select([in_file], [], [], 0.1)[0]):
#print("in while")
event = in_file.read(EVENT_SIZE)
print("Scrollup")
if type == 2 and code==8 and value>1:
# swallow identical events directly after the existing one
while (in_file in select.select([in_file], [], [], 0.3)[0]):
#print("in while")
event = in_file.read(EVENT_SIZE)
print("Scrolldown")
event = in_file.read(EVENT_SIZE)
#print("gug")
in_file.close()