python -m evdev.evtest
evdev.InputDevice represents an input device (think /dev/input/eventX) from which input events can be read. __init__ | |
path | The device that the instance is reading from (/dev/input/eventX) |
fd | Likely a file descriptor |
info | An instance of device.DeviceInfo |
name | |
phys | A string whose value is something like isa0060/serio0/input0 |
uniq | A string |
version | An int |
ff_effects_count | An int |
capabilities() | |
input_props | A list |
leds() | |
set_led() | |
__eq__ | |
__ne__ | |
__fspath__ | |
grab, ungrab | Exclusively grab (or release) a device (EVIOCGRAB). |
grab_context | A context manager that calls ungrab() when the corresponding with block is exited. |
upload_effect | |
erase_effect | |
repeat | |
active_keys() | |
fn | |
absinfo | |
__hash__ |
evdev.UInput … InputEvent are returned by EventIO.read_loop() and EventIO.read(). util.categorize function and the event_factory dictionary). InputEvent | A generic event |
KeyEvent | An event generated by a keyboard or other key-like devices |
RelEvent | An event generated by devices with relative movements (like mice) |
AbsEvent |
evdev.InputEvent for reading, by UInput for writing events. fileno | |
read_loop | Indefinitely returns InputEvent instances. |
read_one | returns an instance of InputEvent |
read | |
need_write | |
write_event, write | Injects an event into the input subsystem. |
close |
include/uapi/linux/input-event-codes.h and linux/input.h (more likely include/uapi/linux/input.h than include/linux/input.h - even though the latter includes the former). from evdev import ecodes
for ecode in dir(ecodes):
print(ecode + ': ' + str(type(getattr(ecodes, ecode))))
from evdev import ecodes
for ev in ecodes.EV:
print(f"{ecodes.EV[ev]:<14} {ev}")
#
# EV_ABS 3
# EV_CNT 32
# EV_FF 21
# EV_FF_STATUS 23
# EV_KEY 1
# EV_LED 17
# EV_MAX 31
# EV_MSC 4
# EV_PWR 22
# EV_REL 2
# EV_REP 20
# EV_SND 18
# EV_SW 5
# EV_SYN 0
# EV_UINPUT 257
# EV_VERSION 65537
ecodes.EV can be used to determine the event type: import evdev
device = evdev.InputDevice('/dev/input/event7')
for event in device.read_loop():
if event.type == evdev.ecodes.EV_KEY:
print(evdev.categorize(event))
elif event.type == evdev.ecodes.EV_SYN:
print('SYN event')
else:
print('Event type: ' + str(event.type))
bustype | |
vendor | |
product | |
version |
bus: 0011, vendor 0001, product 0001, version abba. evdev.util include: list_devices() | Returns a list of strings each of which is areadable devices in a given directory (default directory of course is /dev/input). |
is_device | Checks if a device is a readable and writable character device. |
categorize | Categorizes an event according to its type. This function is somehow related to the event_factory dictionary which maps event types to subclasses of InputEvent. |
resolve_evcodes | Resolves event codes and types to their verbose names. |
resolve_ecodes_dict |
import evdev
devname = 'LITEON Technology USB Multimedia Keyboard'
# 'AT Translated Set 2 keyboard'
devobjs = [ devobj for devobj in [ evdev.InputDevice(devpath)
for devpath in evdev.list_devices() ]
if devobj.name == devname
]
if devobjs == []:
print('no device found')
quit()
devobj=devobjs[0]
print(devobj)
import evdev
devname = 'LITEON Technology USB Multimedia Keyboard'
devobjs = [ devobj for devobj in [ evdev.InputDevice(devpath)
for devpath in evdev.list_devices() ]
if devobj.name == devname
]
if devobjs == []:
print('no device found')
quit()
devobj=devobjs[0]
for ev in devobj.read_loop():
if ev.type == evdev.ecodes.EV_KEY and ev.value == 1:
print(evdev.ecodes.KEY[ev.code])