1
1
use super :: {
2
- DecodeState , Error , KeyCode , KeyEvent , KeyState , ScancodeSet , EXTENDED_KEY_CODE ,
3
- KEY_RELEASE_CODE ,
2
+ DecodeState , Error , KeyCode , KeyEvent , KeyState , ScancodeSet , EXTENDED2_KEY_CODE ,
3
+ EXTENDED_KEY_CODE , KEY_RELEASE_CODE ,
4
4
} ;
5
5
6
6
/// Contains the implementation of Scancode Set 1.
@@ -239,6 +239,11 @@ impl ScancodeSet for ScancodeSet1 {
239
239
_ => Err ( Error :: UnknownKeyCode ) ,
240
240
}
241
241
}
242
+
243
+ /// There are no extended2 scancodes here
244
+ fn map_extended2_scancode ( _code : u8 ) -> Result < KeyCode , Error > {
245
+ Err ( Error :: UnknownKeyCode )
246
+ }
242
247
}
243
248
244
249
/// Contains the implementation of Scancode Set 2.
@@ -252,6 +257,7 @@ impl ScancodeSet for ScancodeSet2 {
252
257
/// Start:
253
258
/// F0 => Release
254
259
/// E0 => Extended
260
+ /// E1 => Extended2 (only used for Pause Key)
255
261
/// xx => Key Down
256
262
///
257
263
/// Release:
@@ -263,21 +269,39 @@ impl ScancodeSet for ScancodeSet2 {
263
269
///
264
270
/// Release Extended:
265
271
/// xxx => Extended Key Up
272
+ ///
273
+ /// Extended2:
274
+ /// F0 => Release Extended2
275
+ /// xx => Extended2 Key Down
276
+ ///
277
+ /// Release Extended2:
278
+ /// xxx => Extended2 Key Up
266
279
fn advance_state ( state : & mut DecodeState , code : u8 ) -> Result < Option < KeyEvent > , Error > {
267
280
match * state {
268
281
DecodeState :: Start => match code {
269
282
EXTENDED_KEY_CODE => {
270
283
* state = DecodeState :: Extended ;
271
284
Ok ( None )
272
285
}
286
+ EXTENDED2_KEY_CODE => {
287
+ * state = DecodeState :: Extended2 ;
288
+ Ok ( None )
289
+ }
273
290
KEY_RELEASE_CODE => {
274
291
* state = DecodeState :: Release ;
275
292
Ok ( None )
276
293
}
277
- _ => Ok ( Some ( KeyEvent :: new (
278
- Self :: map_scancode ( code) ?,
279
- KeyState :: Down ,
280
- ) ) ) ,
294
+ _ => {
295
+ let keycode = Self :: map_scancode ( code) ?;
296
+ if keycode == KeyCode :: TooManyKeys || keycode == KeyCode :: PowerOnTestOk {
297
+ Ok ( Some ( KeyEvent :: new ( keycode, KeyState :: SingleShot ) ) )
298
+ } else {
299
+ Ok ( Some ( KeyEvent :: new (
300
+ Self :: map_scancode ( code) ?,
301
+ KeyState :: Down ,
302
+ ) ) )
303
+ }
304
+ }
281
305
} ,
282
306
DecodeState :: Release => {
283
307
* state = DecodeState :: Start ;
@@ -288,18 +312,41 @@ impl ScancodeSet for ScancodeSet2 {
288
312
* state = DecodeState :: ExtendedRelease ;
289
313
Ok ( None )
290
314
}
315
+ _ => {
316
+ * state = DecodeState :: Start ;
317
+
318
+ let keycode = Self :: map_extended_scancode ( code) ?;
319
+ if keycode == KeyCode :: PrintScreen || keycode == KeyCode :: PrintScreen2 {
320
+ Ok ( Some ( KeyEvent :: new ( keycode, KeyState :: SingleShot ) ) )
321
+ } else {
322
+ Ok ( Some ( KeyEvent :: new ( keycode, KeyState :: Down ) ) )
323
+ }
324
+ }
325
+ } ,
326
+ DecodeState :: ExtendedRelease => {
327
+ * state = DecodeState :: Start ;
328
+ Ok ( Some ( KeyEvent :: new (
329
+ Self :: map_extended_scancode ( code) ?,
330
+ KeyState :: Up ,
331
+ ) ) )
332
+ }
333
+ DecodeState :: Extended2 => match code {
334
+ KEY_RELEASE_CODE => {
335
+ * state = DecodeState :: Extended2Release ;
336
+ Ok ( None )
337
+ }
291
338
_ => {
292
339
* state = DecodeState :: Start ;
293
340
Ok ( Some ( KeyEvent :: new (
294
- Self :: map_extended_scancode ( code) ?,
341
+ Self :: map_extended2_scancode ( code) ?,
295
342
KeyState :: Down ,
296
343
) ) )
297
344
}
298
345
} ,
299
- DecodeState :: ExtendedRelease => {
346
+ DecodeState :: Extended2Release => {
300
347
* state = DecodeState :: Start ;
301
348
Ok ( Some ( KeyEvent :: new (
302
- Self :: map_extended_scancode ( code) ?,
349
+ Self :: map_extended2_scancode ( code) ?,
303
350
KeyState :: Up ,
304
351
) ) )
305
352
}
@@ -309,6 +356,7 @@ impl ScancodeSet for ScancodeSet2 {
309
356
/// Implements the single byte codes for Set 2.
310
357
fn map_scancode ( code : u8 ) -> Result < KeyCode , Error > {
311
358
match code {
359
+ 0x00 => Ok ( KeyCode :: TooManyKeys ) , // 00
312
360
0x01 => Ok ( KeyCode :: F9 ) , // 01
313
361
0x03 => Ok ( KeyCode :: F5 ) , // 03
314
362
0x04 => Ok ( KeyCode :: F3 ) , // 04
@@ -405,6 +453,7 @@ impl ScancodeSet for ScancodeSet2 {
405
453
fn map_extended_scancode ( code : u8 ) -> Result < KeyCode , Error > {
406
454
match code {
407
455
0x11 => Ok ( KeyCode :: AltRight ) , // E011
456
+ 0x12 => Ok ( KeyCode :: PrintScreen ) , // E012 (first half)
408
457
0x14 => Ok ( KeyCode :: ControlRight ) , // E014
409
458
0x1F => Ok ( KeyCode :: WindowsLeft ) , // E01F
410
459
0x27 => Ok ( KeyCode :: WindowsRight ) , // E027
@@ -420,9 +469,17 @@ impl ScancodeSet for ScancodeSet2 {
420
469
0x74 => Ok ( KeyCode :: ArrowRight ) , // E074
421
470
0x75 => Ok ( KeyCode :: ArrowUp ) , // E075
422
471
0x7A => Ok ( KeyCode :: PageDown ) , // E07A
423
- 0x7C => Ok ( KeyCode :: PrintScreen ) , // E07C
472
+ 0x7C => Ok ( KeyCode :: PrintScreen2 ) , // E07C (second half)
424
473
0x7D => Ok ( KeyCode :: PageUp ) , // E07D
425
- 0x7E => Ok ( KeyCode :: Break ) , // E07E
474
+ 0x7E => Ok ( KeyCode :: ScrollLock ) , // E07E
475
+ _ => Err ( Error :: UnknownKeyCode ) ,
476
+ }
477
+ }
478
+
479
+ /// Implements the extended byte codes for set 2 (prefixed with E1)
480
+ fn map_extended2_scancode ( code : u8 ) -> Result < KeyCode , Error > {
481
+ match code {
482
+ 0x14 => Ok ( KeyCode :: PauseBreak ) , // E114
426
483
_ => Err ( Error :: UnknownKeyCode ) ,
427
484
}
428
485
}
0 commit comments