@@ -55,21 +55,18 @@ void Keyboard_Class::begin() {
5555 _set_output (output_list, 0 );
5656}
5757
58- int Keyboard_Class::getKeyCode (Point2D_t keyCoor) {
59- int ret = 0 ;
58+ uint8_t Keyboard_Class::getKey (Point2D_t keyCoor) {
59+ uint8_t ret = 0 ;
6060
6161 if ((keyCoor.x < 0 ) || (keyCoor.y < 0 )) {
6262 return 0 ;
6363 }
64-
65- // ret = (keyCoor.y * 14) + (keyCoor.x + 1);
6664 if (_keys_state_buffer.ctrl || _keys_state_buffer.shift ||
6765 _is_caps_locked) {
68- ret = _key_value_map[keyCoor.y ][keyCoor.x ].value_num_second ;
66+ ret = _key_value_map[keyCoor.y ][keyCoor.x ].value_second ;
6967 } else {
70- ret = _key_value_map[keyCoor.y ][keyCoor.x ].value_num_first ;
68+ ret = _key_value_map[keyCoor.y ][keyCoor.x ].value_first ;
7169 }
72-
7370 return ret;
7471}
7572
@@ -117,10 +114,10 @@ bool Keyboard_Class::isChange() {
117114 }
118115}
119116
120- bool Keyboard_Class::isKeyPressed (int keyCode ) {
117+ bool Keyboard_Class::isKeyPressed (char c ) {
121118 if (_key_list_buffer.size ()) {
122119 for (const auto & i : _key_list_buffer) {
123- if (getKeyCode (i) == keyCode ) return true ;
120+ if (getKey (i) == c ) return true ;
124121 }
125122 }
126123 return false ;
@@ -130,66 +127,94 @@ bool Keyboard_Class::isKeyPressed(int keyCode) {
130127
131128void Keyboard_Class::updateKeysState () {
132129 _keys_state_buffer.reset ();
133- _key_values_without_special_keys.clear ();
130+ _key_pos_print_keys.clear ();
131+ _key_pos_hid_keys.clear ();
132+ _key_pos_modifier_keys.clear ();
134133
135134 // Get special keys
136135 for (auto & i : _key_list_buffer) {
137- if (strcmp (getKeyValue (i).value_first , " tab" ) == 0 ) {
138- _keys_state_buffer.tab = true ;
139- continue ;
140- }
141-
142- if (strcmp (getKeyValue (i).value_first , " fn" ) == 0 ) {
136+ // modifier
137+ if (getKeyValue (i).value_first == KEY_FN) {
143138 _keys_state_buffer.fn = true ;
144139 continue ;
145140 }
146-
147- if (strcmp (getKeyValue (i).value_first , " shift" ) == 0 ) {
148- _keys_state_buffer.shift = true ;
141+ if (getKeyValue (i).value_first == KEY_OPT) {
142+ _keys_state_buffer.opt = true ;
149143 continue ;
150144 }
151145
152- if (strcmp ( getKeyValue (i).value_first , " ctrl " ) == 0 ) {
146+ if (getKeyValue (i).value_first == KEY_LEFT_CTRL ) {
153147 _keys_state_buffer.ctrl = true ;
148+ _key_pos_modifier_keys.push_back (i);
154149 continue ;
155150 }
156- if (strcmp (getKeyValue (i).value_first , " opt" ) == 0 ) {
157- _keys_state_buffer.opt = true ;
151+
152+ if (getKeyValue (i).value_first == KEY_LEFT_SHIFT) {
153+ _keys_state_buffer.shift = true ;
154+ _key_pos_modifier_keys.push_back (i);
158155 continue ;
159156 }
160157
161- if (strcmp ( getKeyValue (i).value_first , " alt " ) == 0 ) {
158+ if (getKeyValue (i).value_first == KEY_LEFT_ALT ) {
162159 _keys_state_buffer.alt = true ;
160+ _key_pos_modifier_keys.push_back (i);
163161 continue ;
164162 }
165163
166- if (strcmp (getKeyValue (i).value_first , " del" ) == 0 ) {
164+ // function
165+ if (getKeyValue (i).value_first == KEY_TAB) {
166+ _keys_state_buffer.tab = true ;
167+ _key_pos_hid_keys.push_back (i);
168+ continue ;
169+ }
170+
171+ if (getKeyValue (i).value_first == KEY_BACKSPACE) {
167172 _keys_state_buffer.del = true ;
173+ _key_pos_hid_keys.push_back (i);
168174 continue ;
169175 }
170176
171- if (strcmp ( getKeyValue (i).value_first , " enter " ) == 0 ) {
177+ if (getKeyValue (i).value_first == KEY_ENTER ) {
172178 _keys_state_buffer.enter = true ;
179+ _key_pos_hid_keys.push_back (i);
173180 continue ;
174181 }
175182
176- if (strcmp ( getKeyValue (i).value_first , " space " ) == 0 ) {
183+ if (getKeyValue (i).value_first == ' ' ) {
177184 _keys_state_buffer.space = true ;
178- continue ;
179185 }
186+ _key_pos_hid_keys.push_back (i);
187+ _key_pos_print_keys.push_back (i);
188+ }
189+
190+ for (auto & i : _key_pos_modifier_keys) {
191+ uint8_t key = getKeyValue (i).value_first ;
192+ _keys_state_buffer.modifier_keys .push_back (key);
193+ }
194+
195+ for (auto & k : _keys_state_buffer.modifier_keys ) {
196+ _keys_state_buffer.modifiers |= (1 << (k - 0x80 ));
197+ }
180198
181- _key_values_without_special_keys.push_back (i);
199+ for (auto & i : _key_pos_hid_keys) {
200+ uint8_t k = getKeyValue (i).value_first ;
201+ if (k == KEY_TAB || k == KEY_BACKSPACE || k == KEY_ENTER) {
202+ _keys_state_buffer.hid_keys .push_back (k);
203+ continue ;
204+ }
205+ uint8_t key = _kb_asciimap[k];
206+ if (key) {
207+ _keys_state_buffer.hid_keys .push_back (key);
208+ }
182209 }
183210
184211 // Deal what left
185- for (auto & i : _key_values_without_special_keys ) {
212+ for (auto & i : _key_pos_print_keys ) {
186213 if (_keys_state_buffer.ctrl || _keys_state_buffer.shift ||
187214 _is_caps_locked) {
188- _keys_state_buffer.values .push_back (*getKeyValue (i).value_second );
189- _keys_state_buffer.keys .push_back (getKeyValue (i).value_num_second );
215+ _keys_state_buffer.word .push_back (getKeyValue (i).value_second );
190216 } else {
191- _keys_state_buffer.values .push_back (*getKeyValue (i).value_first );
192- _keys_state_buffer.keys .push_back (getKeyValue (i).value_num_first );
217+ _keys_state_buffer.word .push_back (getKeyValue (i).value_first );
193218 }
194219 }
195220}
0 commit comments