Format/dev/input / event*
Jaki jest "format" urządzeń znakowych znajdujących się w /dev/input/event*
?
Innymi słowy, jak Mogę dekodować strumień znaków? Przykład Pythona byłby bardzo mile widziany.
5 answers
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-01-19 05:06:17
Prosty i surowy czytnik można po prostu zrobić za pomocą:
#!/usr/bin/python
import struct
import time
import sys
infile_path = "/dev/input/event" + (sys.argv[1] if len(sys.argv) > 1 else "0")
"""
FORMAT represents the format used by linux kernel input event struct
See https://github.com/torvalds/linux/blob/v5.5-rc5/include/uapi/linux/input.h#L28
Stands for: 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))
else:
# Events with code, type and value == 0 are "separator" events
print("===========================================")
event = in_file.read(EVENT_SIZE)
in_file.close()
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-01-07 12:09:49
Format jest opisany w Documentation/input/input.txt
plik w źródle Linuksa. Zasadniczo z pliku odczytujemy struktury następującej formy:
struct input_event {
struct timeval time;
unsigned short type;
unsigned short code;
unsigned int value;
};
type
i {[3] } są wartościami zdefiniowanymi w linux/input.h
. Na przykład,
Typ może być EV_REL
dla względnego momentu myszy lub EV_KEY
dla
klawiatura, a code
jest kodem klawiatury, lub REL_X
lub ABS_X
dla
mysz.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-02-20 23:08:44
Pakietpython-evdev zapewnia powiązania z interfejsem urządzenia zdarzenia. Krótki przykład użycia to:
from evdev import InputDevice
from select import select
dev = InputDevice('/dev/input/event1')
while True:
r,w,x = select([dev], [], [])
for event in dev.read():
print(event)
# event at 1337427573.061822, code 01, type 02, val 01
# event at 1337427573.061846, code 00, type 00, val 00
Należy pamiętać, że w przeciwieństwie do bardzo wygodnych, czysto Pythonicznych modułów wymienionych do tej pory, evdev zawiera rozszerzenia C. Ich zbudowanie wymaga zainstalowania nagłówków Jądra Pythona.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2020-01-19 05:20:59
Dane mają postać input_event
struktur; Zobacz http://www.thelinuxdaily.com/2010/05/grab-raw-keyboard-input-from-event-device-node-devinputevent/{[4]na przykład C. Definicja struct jest na (na przykład) http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/include/linux/input.h?v=2.6.11.8. zauważ, że będziesz musiał użyć kilku wywołań ioctl
, Aby uzyskać informacje o urządzeniu przed odczytaniem z niego.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-02-20 23:07:30