3838# http://www.kernel.org/doc/Documentation/input/event-codes.txt
3939
4040# pylint: disable=no-name-in-module
41+ from typing import Final
4142from .ecodes import ABS , EV_ABS , EV_KEY , EV_REL , EV_SYN , KEY , REL , SYN , keys
4243
4344
@@ -48,21 +49,21 @@ class InputEvent:
4849
4950 def __init__ (self , sec , usec , type , code , value ):
5051 #: Time in seconds since epoch at which event occurred.
51- self .sec = sec
52+ self .sec : int = sec
5253
5354 #: Microsecond portion of the timestamp.
54- self .usec = usec
55+ self .usec : int = usec
5556
5657 #: Event type - one of ``ecodes.EV_*``.
57- self .type = type
58+ self .type : int = type
5859
5960 #: Event code related to the event type.
60- self .code = code
61+ self .code : int = code
6162
6263 #: Event value related to the event type.
63- self .value = value
64+ self .value : int = value
6465
65- def timestamp (self ):
66+ def timestamp (self ) -> float :
6667 """Return event timestamp as a float."""
6768 return self .sec + (self .usec / 1000000.0 )
6869
@@ -78,20 +79,20 @@ def __repr__(self):
7879class KeyEvent :
7980 """An event generated by a keyboard, button or other key-like devices."""
8081
81- key_up = 0x0
82- key_down = 0x1
83- key_hold = 0x2
82+ key_up : Final [ int ] = 0x0
83+ key_down : Final [ int ] = 0x1
84+ key_hold : Final [ int ] = 0x2
8485
8586 __slots__ = "scancode" , "keycode" , "keystate" , "event"
8687
87- def __init__ (self , event , allow_unknown = False ):
88+ def __init__ (self , event : InputEvent , allow_unknown : bool = False ):
8889 """
8990 The ``allow_unknown`` argument determines what to do in the event of an event code
9091 for which a key code cannot be found. If ``False`` a ``KeyError`` will be raised.
9192 If ``True`` the keycode will be set to the hex value of the event code.
9293 """
9394
94- self .scancode = event .code
95+ self .scancode : int = event .code
9596
9697 if event .value == 0 :
9798 self .keystate = KeyEvent .key_up
@@ -109,7 +110,7 @@ def __init__(self, event, allow_unknown=False):
109110 raise
110111
111112 #: Reference to an :class:`InputEvent` instance.
112- self .event = event
113+ self .event : InputEvent = event
113114
114115 def __str__ (self ):
115116 try :
@@ -129,9 +130,9 @@ class RelEvent:
129130
130131 __slots__ = "event"
131132
132- def __init__ (self , event ):
133+ def __init__ (self , event : InputEvent ):
133134 #: Reference to an :class:`InputEvent` instance.
134- self .event = event
135+ self .event : InputEvent = event
135136
136137 def __str__ (self ):
137138 msg = "relative axis event at {:f}, {}"
@@ -146,9 +147,9 @@ class AbsEvent:
146147
147148 __slots__ = "event"
148149
149- def __init__ (self , event ):
150+ def __init__ (self , event : InputEvent ):
150151 #: Reference to an :class:`InputEvent` instance.
151- self .event = event
152+ self .event : InputEvent = event
152153
153154 def __str__ (self ):
154155 msg = "absolute axis event at {:f}, {}"
@@ -166,9 +167,9 @@ class SynEvent:
166167
167168 __slots__ = "event"
168169
169- def __init__ (self , event ):
170+ def __init__ (self , event : InputEvent ):
170171 #: Reference to an :class:`InputEvent` instance.
171- self .event = event
172+ self .event : InputEvent = event
172173
173174 def __str__ (self ):
174175 msg = "synchronization event at {:f}, {}"
0 commit comments