1212 kb_asciimap ,
1313)
1414
15- Point2D = namedtuple (' Point2D' , ['x' , 'y' ])
16- Chart = namedtuple (' Chart' , [' value' , ' x_1' , ' x_2' ])
17- KeyValue = namedtuple (' KeyValue' , [' first' , ' second' ])
15+ Point2D = namedtuple (" Point2D" , ["x" , "y" ])
16+ Chart = namedtuple (" Chart" , [" value" , " x_1" , " x_2" ])
17+ KeyValue = namedtuple (" KeyValue" , [" first" , " second" ])
1818
1919_X_map_chart = (
2020 Chart (1 , 0 , 1 ),
2828
2929_key_value_map = (
3030 (
31- KeyValue (ord ('`' ), ord ('~' )),
32- KeyValue (ord ('1' ), ord ('!' )),
33- KeyValue (ord ('2' ), ord ('@' )),
34- KeyValue (ord ('3' ), ord ('#' )),
35- KeyValue (ord ('4' ), ord ('$' )),
36- KeyValue (ord ('5' ), ord ('%' )),
37- KeyValue (ord ('6' ), ord ('^' )),
38- KeyValue (ord ('7' ), ord ('&' )),
39- KeyValue (ord ('8' ), ord ('*' )),
40- KeyValue (ord ('9' ), ord ('(' )),
41- KeyValue (ord ('0' ), ord (')' )),
42- KeyValue (ord ('-' ), ord ('_' )),
43- KeyValue (ord ('=' ), ord ('+' )),
31+ KeyValue (ord ("`" ), ord ("~" )),
32+ KeyValue (ord ("1" ), ord ("!" )),
33+ KeyValue (ord ("2" ), ord ("@" )),
34+ KeyValue (ord ("3" ), ord ("#" )),
35+ KeyValue (ord ("4" ), ord ("$" )),
36+ KeyValue (ord ("5" ), ord ("%" )),
37+ KeyValue (ord ("6" ), ord ("^" )),
38+ KeyValue (ord ("7" ), ord ("&" )),
39+ KeyValue (ord ("8" ), ord ("*" )),
40+ KeyValue (ord ("9" ), ord ("(" )),
41+ KeyValue (ord ("0" ), ord (")" )),
42+ KeyValue (ord ("-" ), ord ("_" )),
43+ KeyValue (ord ("=" ), ord ("+" )),
4444 KeyValue (KEY_BACKSPACE , KEY_BACKSPACE ),
4545 ),
4646 (
4747 KeyValue (KEY_TAB , KEY_TAB ),
48- KeyValue (ord ('q' ), ord ('Q' )),
49- KeyValue (ord ('w' ), ord ('W' )),
50- KeyValue (ord ('e' ), ord ('E' )),
51- KeyValue (ord ('r' ), ord ('R' )),
52- KeyValue (ord ('t' ), ord ('T' )),
53- KeyValue (ord ('y' ), ord ('Y' )),
54- KeyValue (ord ('u' ), ord ('U' )),
55- KeyValue (ord ('i' ), ord ('I' )),
56- KeyValue (ord ('o' ), ord ('O' )),
57- KeyValue (ord ('p' ), ord ('P' )),
58- KeyValue (ord ('[' ), ord ('{' )),
59- KeyValue (ord (']' ), ord ('}' )),
60- KeyValue (ord (' \\ ' ), ord ('|' )),
48+ KeyValue (ord ("q" ), ord ("Q" )),
49+ KeyValue (ord ("w" ), ord ("W" )),
50+ KeyValue (ord ("e" ), ord ("E" )),
51+ KeyValue (ord ("r" ), ord ("R" )),
52+ KeyValue (ord ("t" ), ord ("T" )),
53+ KeyValue (ord ("y" ), ord ("Y" )),
54+ KeyValue (ord ("u" ), ord ("U" )),
55+ KeyValue (ord ("i" ), ord ("I" )),
56+ KeyValue (ord ("o" ), ord ("O" )),
57+ KeyValue (ord ("p" ), ord ("P" )),
58+ KeyValue (ord ("[" ), ord ("{" )),
59+ KeyValue (ord ("]" ), ord ("}" )),
60+ KeyValue (ord (" \\ " ), ord ("|" )),
6161 ),
6262 (
6363 KeyValue (KEY_FN , KEY_FN ),
6464 KeyValue (KEY_LEFT_SHIFT , KEY_LEFT_SHIFT ),
65- KeyValue (ord ('a' ), ord ('A' )),
66- KeyValue (ord ('s' ), ord ('S' )),
67- KeyValue (ord ('d' ), ord ('D' )),
68- KeyValue (ord ('f' ), ord ('F' )),
69- KeyValue (ord ('g' ), ord ('G' )),
70- KeyValue (ord ('h' ), ord ('H' )),
71- KeyValue (ord ('j' ), ord ('J' )),
72- KeyValue (ord ('k' ), ord ('K' )),
73- KeyValue (ord ('l' ), ord ('L' )),
74- KeyValue (ord (';' ), ord (':' )),
75- KeyValue (ord (' \' ' ), ord ('\ " ' )),
65+ KeyValue (ord ("a" ), ord ("A" )),
66+ KeyValue (ord ("s" ), ord ("S" )),
67+ KeyValue (ord ("d" ), ord ("D" )),
68+ KeyValue (ord ("f" ), ord ("F" )),
69+ KeyValue (ord ("g" ), ord ("G" )),
70+ KeyValue (ord ("h" ), ord ("H" )),
71+ KeyValue (ord ("j" ), ord ("J" )),
72+ KeyValue (ord ("k" ), ord ("K" )),
73+ KeyValue (ord ("l" ), ord ("L" )),
74+ KeyValue (ord (";" ), ord (":" )),
75+ KeyValue (ord ("'" ), ord ('"' )),
7676 KeyValue (KEY_ENTER , KEY_ENTER ),
7777 ),
7878 (
7979 KeyValue (KEY_LEFT_CTRL , KEY_LEFT_CTRL ),
8080 KeyValue (KEY_OPT , KEY_OPT ),
8181 KeyValue (KEY_LEFT_ALT , KEY_LEFT_ALT ),
82- KeyValue (ord ('z' ), ord ('Z' )),
83- KeyValue (ord ('x' ), ord ('X' )),
84- KeyValue (ord ('c' ), ord ('C' )),
85- KeyValue (ord ('v' ), ord ('V' )),
86- KeyValue (ord ('b' ), ord ('B' )),
87- KeyValue (ord ('n' ), ord ('N' )),
88- KeyValue (ord ('m' ), ord ('M' )),
89- KeyValue (ord (',' ), ord ('<' )),
90- KeyValue (ord ('.' ), ord ('>' )),
91- KeyValue (ord ('/' ), ord ('?' )),
92- KeyValue (ord (' ' ), ord (' ' )),
82+ KeyValue (ord ("z" ), ord ("Z" )),
83+ KeyValue (ord ("x" ), ord ("X" )),
84+ KeyValue (ord ("c" ), ord ("C" )),
85+ KeyValue (ord ("v" ), ord ("V" )),
86+ KeyValue (ord ("b" ), ord ("B" )),
87+ KeyValue (ord ("n" ), ord ("N" )),
88+ KeyValue (ord ("m" ), ord ("M" )),
89+ KeyValue (ord ("," ), ord ("<" )),
90+ KeyValue (ord ("." ), ord (">" )),
91+ KeyValue (ord ("/" ), ord ("?" )),
92+ KeyValue (ord (" " ), ord (" " )),
9393 ),
9494)
9595
9696
9797class KeysState :
98- tab = False
99- fn = False
100- shift = False
101- ctrl = False
102- opt = False
103- alt = False
104- delete = False
105- enter = False
106- space = False
107- modifiers = 0
98+ tab = False
99+ fn = False
100+ shift = False
101+ ctrl = False
102+ opt = False
103+ alt = False
104+ delete = False
105+ enter = False
106+ space = False
107+ modifiers = 0
108108
109109 def __init__ (self ) -> None :
110110 self .word = bytearray (0 )
111111 self .hid_keys = bytearray (0 )
112112 self .modifier_keys = bytearray (0 )
113113
114114 def reset (self ):
115- self .tab = False
116- self .fn = False
117- self .shift = False
118- self .ctrl = False
119- self .opt = False
120- self .alt = False
121- self .delete = False
122- self .enter = False
123- self .space = False
124- self .modifiers = 0
115+ self .tab = False
116+ self .fn = False
117+ self .shift = False
118+ self .ctrl = False
119+ self .opt = False
120+ self .alt = False
121+ self .delete = False
122+ self .enter = False
123+ self .space = False
124+ self .modifiers = 0
125125 self .word = bytearray (0 )
126126 self .hid_keys = bytearray (0 )
127127 self .modifier_keys = bytearray (0 )
128128
129129
130130class Keyboard :
131-
132131 def __init__ (self ):
133- self .output_list = [ Pin (id , Pin .OUT , Pin .PULL_DOWN ) for id in (8 , 9 , 11 ) ]
134- self .input_list = [ Pin (id , Pin .IN , Pin .PULL_UP ) for id in (13 , 15 , 3 , 4 , 5 , 6 , 7 ) ]
132+ self .output_list = [Pin (id , Pin .OUT , Pin .PULL_DOWN ) for id in (8 , 9 , 11 )]
133+ self .input_list = [Pin (id , Pin .IN , Pin .PULL_UP ) for id in (13 , 15 , 3 , 4 , 5 , 6 , 7 )]
135134
136135 for pin in self .output_list :
137136 pin .value (0 )
@@ -148,20 +147,20 @@ def __init__(self):
148147
149148 @staticmethod
150149 def _set_output (pin_list , output ):
151- output = output & 0B00000111
152- pin_list [0 ].value (output & 0B00000001 )
153- pin_list [1 ].value (output & 0B00000010 )
154- pin_list [2 ].value (output & 0B00000100 )
150+ output = output & 0b00000111
151+ pin_list [0 ].value (output & 0b00000001 )
152+ pin_list [1 ].value (output & 0b00000010 )
153+ pin_list [2 ].value (output & 0b00000100 )
155154
156155 @staticmethod
157156 def _get_input (pin_list ):
158- buffer = 0x00
157+ buffer = 0x00
159158 pin_value = 0x00
160159
161160 for i in range (7 ):
162161 pin_value = 0x00 if pin_list [i ].value () == 1 else 0x01
163162 pin_value = pin_value << i
164- buffer = buffer | pin_value
163+ buffer = buffer | pin_value
165164
166165 return buffer
167166
@@ -171,11 +170,7 @@ def getKey(self, point: Point2D):
171170 if point .x < 0 or point .y < 0 :
172171 return ret
173172
174- if (
175- self ._keys_state_buffer .ctrl
176- or self ._keys_state_buffer .shift
177- or self ._is_caps_locked
178- ):
173+ if self ._keys_state_buffer .ctrl or self ._keys_state_buffer .shift or self ._is_caps_locked :
179174 ret = _key_value_map [point .x ][point .y ].second
180175 else :
181176 ret = _key_value_map [point .x ][point .y ].first
@@ -272,7 +267,7 @@ def updateKeysState(self):
272267 self ._key_pos_hid_keys .append (i )
273268 continue
274269
275- if self .getKeyValue (i ).first == ' ' :
270+ if self .getKeyValue (i ).first == " " :
276271 self ._keys_state_buffer .space = True
277272
278273 self ._key_pos_hid_keys .append (i )
@@ -283,7 +278,7 @@ def updateKeysState(self):
283278 self ._keys_state_buffer .modifier_keys .append (key )
284279
285280 for k in self ._keys_state_buffer .modifier_keys :
286- self ._keys_state_buffer .modifiers |= ( 1 << (k - 0x80 ) )
281+ self ._keys_state_buffer .modifiers |= 1 << (k - 0x80 )
287282
288283 for i in self ._key_pos_hid_keys :
289284 k = self .getKeyValue (i ).first
0 commit comments