fix(evdev): Resource-Leak und Handling unbekannter Keycodes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,16 +11,25 @@ from evdev import InputDevice, ecodes
|
||||
def find_all_keyboards() -> list[InputDevice]:
|
||||
"""Gibt alle Input-Devices zurück, die EV_KEY-Events liefern können."""
|
||||
keyboards: list[InputDevice] = []
|
||||
for path in evdev.list_devices():
|
||||
try:
|
||||
device = InputDevice(path)
|
||||
except (PermissionError, OSError):
|
||||
continue
|
||||
capabilities = device.capabilities()
|
||||
if ecodes.EV_KEY in capabilities:
|
||||
keyboards.append(device)
|
||||
else:
|
||||
device.close()
|
||||
try:
|
||||
for path in evdev.list_devices():
|
||||
try:
|
||||
device = InputDevice(path)
|
||||
except (PermissionError, OSError):
|
||||
continue
|
||||
try:
|
||||
capabilities = device.capabilities()
|
||||
except OSError:
|
||||
device.close()
|
||||
continue
|
||||
if ecodes.EV_KEY in capabilities:
|
||||
keyboards.append(device)
|
||||
else:
|
||||
device.close()
|
||||
except BaseException:
|
||||
for dev in keyboards:
|
||||
dev.close()
|
||||
raise
|
||||
return keyboards
|
||||
|
||||
|
||||
@@ -58,8 +67,10 @@ def record_hotkey(
|
||||
dev: InputDevice = key.data
|
||||
for event in dev.read():
|
||||
if event.type == ecodes.EV_KEY and event.value == 1:
|
||||
captured = _keycode_to_name(event.code)
|
||||
break
|
||||
name = _keycode_to_name(event.code)
|
||||
if name:
|
||||
captured = name
|
||||
break
|
||||
if captured:
|
||||
break
|
||||
|
||||
|
||||
Reference in New Issue
Block a user