10
10
"""
11
11
12
12
13
+ try :
14
+ from typing import Tuple
15
+ from .keyboard import Keyboard
16
+ except ImportError :
17
+ pass
18
+
19
+
13
20
__version__ = "0.0.0-auto.0"
14
21
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_HID.git"
15
22
@@ -32,7 +39,7 @@ class KeyboardLayoutBase:
32
39
HIGHER_ASCII = {}
33
40
COMBINED_KEYS = {}
34
41
35
- def __init__ (self , keyboard ) :
42
+ def __init__ (self , keyboard : Keyboard ) -> None :
36
43
"""Specify the layout for the given keyboard.
37
44
38
45
:param keyboard: a Keyboard object. Write characters to this keyboard when requested.
@@ -44,7 +51,7 @@ def __init__(self, keyboard):
44
51
"""
45
52
self .keyboard = keyboard
46
53
47
- def _write (self , keycode , altgr = False ):
54
+ def _write (self , keycode : int , altgr : bool = False ) -> None :
48
55
"""Type a key combination based on shift bit and altgr bool
49
56
50
57
:param keycode: int value of the keycode, with the shift bit.
@@ -60,7 +67,7 @@ def _write(self, keycode, altgr=False):
60
67
self .keyboard .press (keycode )
61
68
self .keyboard .release_all ()
62
69
63
- def write (self , string ) :
70
+ def write (self , string : str ) -> None :
64
71
"""Type the string by pressing and releasing keys on my keyboard.
65
72
66
73
:param string: A string of ASCII characters.
@@ -94,7 +101,7 @@ def write(self, string):
94
101
)
95
102
)
96
103
97
- def keycodes (self , char ) :
104
+ def keycodes (self , char : str ) -> Tuple [ int , ...] :
98
105
"""Return a tuple of keycodes needed to type the given character.
99
106
100
107
:param char: A single UTF8 character in a string.
@@ -131,7 +138,7 @@ def keycodes(self, char):
131
138
132
139
return codes
133
140
134
- def _above128char_to_keycode (self , char ) :
141
+ def _above128char_to_keycode (self , char : str ) -> int :
135
142
"""Return keycode for above 128 ascii codes.
136
143
137
144
A character can be indexed by the char itself or its int ord() value.
@@ -145,7 +152,7 @@ def _above128char_to_keycode(self, char):
145
152
return self .HIGHER_ASCII [char ]
146
153
return 0
147
154
148
- def _char_to_keycode (self , char ) :
155
+ def _char_to_keycode (self , char : str ) -> int :
149
156
"""Return the HID keycode for the given ASCII character, with the SHIFT_FLAG possibly set.
150
157
151
158
If the character requires pressing the Shift key, the SHIFT_FLAG bit is set.
0 commit comments