2828import functools
2929from pathlib import Path
3030import signal
31+ from typing import Optional , Sequence , cast
3132
3233
3334import evdev
34- from evdev import ecodes , InputDevice , UInput
35+ from evdev import KeyEvent , ecodes , InputDevice , UInput
3536import pyudev
3637from xdg import BaseDirectory
3738import yaml
@@ -304,7 +305,7 @@ def register_device(device, loop: AbstractEventLoop):
304305 return None
305306 input .grab ()
306307
307- caps = input .capabilities ()
308+ caps = cast ( dict [ int , Sequence [ int ]], input .capabilities () )
308309 # EV_SYN is automatically added to uinput devices
309310 del caps [ecodes .EV_SYN ]
310311
@@ -409,14 +410,15 @@ def list_devices():
409410
410411
411412def read_events (req_device ):
413+ found : Optional [InputDevice ] = None
412414 for device in list_devices ():
413415 # Look in all 3 identifiers + event number
414416 if req_device in device or req_device == device [0 ].replace (
415417 "/dev/input/event" , ""
416418 ):
417- found = evdev . InputDevice (device [0 ])
419+ found = InputDevice (device [0 ])
418420
419- if "found" not in locals () :
421+ if not found :
420422 print (
421423 "Device not found. \n "
422424 "Please use --list-devices to view a list of available devices."
@@ -430,6 +432,7 @@ def read_events(req_device):
430432 try :
431433 if event .type == evdev .ecodes .EV_KEY :
432434 categorized = evdev .categorize (event )
435+ assert isinstance (categorized , KeyEvent )
433436 if categorized .keystate == 1 :
434437 keycode = (
435438 categorized .keycode
0 commit comments