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
@@ -50,7 +57,7 @@ class KeyboardLayoutBase:
50
57
``KKK KKKK`` is the (low) ASCII code for the second character.
51
58
"""
52
59
53
- def __init__ (self , keyboard ) :
60
+ def __init__ (self , keyboard : Keyboard ) -> None :
54
61
"""Specify the layout for the given keyboard.
55
62
56
63
:param keyboard: a Keyboard object. Write characters to this keyboard when requested.
@@ -62,7 +69,7 @@ def __init__(self, keyboard):
62
69
"""
63
70
self .keyboard = keyboard
64
71
65
- def _write (self , keycode , altgr = False ):
72
+ def _write (self , keycode : int , altgr : bool = False ) -> None :
66
73
"""Type a key combination based on shift bit and altgr bool
67
74
68
75
:param keycode: int value of the keycode, with the shift bit.
@@ -78,7 +85,7 @@ def _write(self, keycode, altgr=False):
78
85
self .keyboard .press (keycode )
79
86
self .keyboard .release_all ()
80
87
81
- def write (self , string ) :
88
+ def write (self , string : str ) -> None :
82
89
"""Type the string by pressing and releasing keys on my keyboard.
83
90
84
91
:param string: A string of UTF-8 characters to convert to key presses and send.
@@ -112,7 +119,7 @@ def write(self, string):
112
119
)
113
120
)
114
121
115
- def keycodes (self , char ) :
122
+ def keycodes (self , char : str ) -> Tuple [ int , ...] :
116
123
"""Return a tuple of keycodes needed to type the given character.
117
124
118
125
:param char: A single UTF8 character in a string.
@@ -149,7 +156,7 @@ def keycodes(self, char):
149
156
150
157
return codes
151
158
152
- def _above128char_to_keycode (self , char ) :
159
+ def _above128char_to_keycode (self , char : str ) -> int :
153
160
"""Return keycode for above 128 utf8 codes.
154
161
155
162
A character can be indexed by the char itself or its int ord() value.
@@ -163,7 +170,7 @@ def _above128char_to_keycode(self, char):
163
170
return self .HIGHER_ASCII [char ]
164
171
return 0
165
172
166
- def _char_to_keycode (self , char ) :
173
+ def _char_to_keycode (self , char : str ) -> int :
167
174
"""Return the HID keycode for the given character, with the SHIFT_FLAG possibly set.
168
175
169
176
If the character requires pressing the Shift key, the SHIFT_FLAG bit is set.
0 commit comments