@@ -2669,6 +2669,71 @@ mod test {
2669
2669
let events: Vec < KeyEvent > = iter. collect ( ) ;
2670
2670
assert ! ( events. is_empty( ) ) ;
2671
2671
}
2672
+
2673
+ #[ test]
2674
+ fn usb_reports ( ) {
2675
+ // Reports, as captured with `sudo usbhid-dump -a 1:4 -es | tee capture.log`
2676
+ let reports = [
2677
+ UsbBootKeyboardReport { modifiers : 0x02 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2678
+ UsbBootKeyboardReport { modifiers : 0x02 , keys : [ 0x0B , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2679
+ UsbBootKeyboardReport { modifiers : 0x02 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2680
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2681
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x08 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2682
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2683
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x0F , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2684
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2685
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x0F , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2686
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2687
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x12 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2688
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2689
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x2C , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2690
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2691
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x17 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2692
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2693
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x0B , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2694
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2695
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x0C , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2696
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2697
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x16 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2698
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2699
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x2C , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2700
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2701
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x0C , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2702
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2703
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x16 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2704
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2705
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x2C , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2706
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2707
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x04 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2708
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2709
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x2C , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2710
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2711
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x17 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2712
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2713
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x08 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2714
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2715
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x16 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2716
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2717
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x17 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2718
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2719
+ UsbBootKeyboardReport { modifiers : 0x02 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2720
+ UsbBootKeyboardReport { modifiers : 0x02 , keys : [ 0x1E , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2721
+ UsbBootKeyboardReport { modifiers : 0x02 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2722
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2723
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x28 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2724
+ UsbBootKeyboardReport { modifiers : 0x00 , keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] } ,
2725
+ ] ;
2726
+ let mut output = String :: new ( ) ;
2727
+ let mut keyboard = UsbKeyboard :: new ( layouts:: Us104Key , HandleControl :: MapLettersToUnicode ) ;
2728
+ for report in reports. iter ( ) {
2729
+ for ev in keyboard. handle_report ( report) {
2730
+ if let DecodedKey :: Unicode ( ch) = ev {
2731
+ output. push ( ch) ;
2732
+ }
2733
+ }
2734
+ }
2735
+ assert_eq ! ( "Hello this is a test!\n " , output) ;
2736
+ }
2672
2737
}
2673
2738
2674
2739
// ****************************************************************************
0 commit comments