@@ -2669,6 +2669,215 @@ 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 {
2678
+ modifiers : 0x02 ,
2679
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2680
+ } ,
2681
+ UsbBootKeyboardReport {
2682
+ modifiers : 0x02 ,
2683
+ keys : [ 0x0B , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2684
+ } ,
2685
+ UsbBootKeyboardReport {
2686
+ modifiers : 0x02 ,
2687
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2688
+ } ,
2689
+ UsbBootKeyboardReport {
2690
+ modifiers : 0x00 ,
2691
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2692
+ } ,
2693
+ UsbBootKeyboardReport {
2694
+ modifiers : 0x00 ,
2695
+ keys : [ 0x08 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2696
+ } ,
2697
+ UsbBootKeyboardReport {
2698
+ modifiers : 0x00 ,
2699
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2700
+ } ,
2701
+ UsbBootKeyboardReport {
2702
+ modifiers : 0x00 ,
2703
+ keys : [ 0x0F , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2704
+ } ,
2705
+ UsbBootKeyboardReport {
2706
+ modifiers : 0x00 ,
2707
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2708
+ } ,
2709
+ UsbBootKeyboardReport {
2710
+ modifiers : 0x00 ,
2711
+ keys : [ 0x0F , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2712
+ } ,
2713
+ UsbBootKeyboardReport {
2714
+ modifiers : 0x00 ,
2715
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2716
+ } ,
2717
+ UsbBootKeyboardReport {
2718
+ modifiers : 0x00 ,
2719
+ keys : [ 0x12 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2720
+ } ,
2721
+ UsbBootKeyboardReport {
2722
+ modifiers : 0x00 ,
2723
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2724
+ } ,
2725
+ UsbBootKeyboardReport {
2726
+ modifiers : 0x00 ,
2727
+ keys : [ 0x2C , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2728
+ } ,
2729
+ UsbBootKeyboardReport {
2730
+ modifiers : 0x00 ,
2731
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2732
+ } ,
2733
+ UsbBootKeyboardReport {
2734
+ modifiers : 0x00 ,
2735
+ keys : [ 0x17 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2736
+ } ,
2737
+ UsbBootKeyboardReport {
2738
+ modifiers : 0x00 ,
2739
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2740
+ } ,
2741
+ UsbBootKeyboardReport {
2742
+ modifiers : 0x00 ,
2743
+ keys : [ 0x0B , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2744
+ } ,
2745
+ UsbBootKeyboardReport {
2746
+ modifiers : 0x00 ,
2747
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2748
+ } ,
2749
+ UsbBootKeyboardReport {
2750
+ modifiers : 0x00 ,
2751
+ keys : [ 0x0C , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2752
+ } ,
2753
+ UsbBootKeyboardReport {
2754
+ modifiers : 0x00 ,
2755
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2756
+ } ,
2757
+ UsbBootKeyboardReport {
2758
+ modifiers : 0x00 ,
2759
+ keys : [ 0x16 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2760
+ } ,
2761
+ UsbBootKeyboardReport {
2762
+ modifiers : 0x00 ,
2763
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2764
+ } ,
2765
+ UsbBootKeyboardReport {
2766
+ modifiers : 0x00 ,
2767
+ keys : [ 0x2C , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2768
+ } ,
2769
+ UsbBootKeyboardReport {
2770
+ modifiers : 0x00 ,
2771
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2772
+ } ,
2773
+ UsbBootKeyboardReport {
2774
+ modifiers : 0x00 ,
2775
+ keys : [ 0x0C , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2776
+ } ,
2777
+ UsbBootKeyboardReport {
2778
+ modifiers : 0x00 ,
2779
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2780
+ } ,
2781
+ UsbBootKeyboardReport {
2782
+ modifiers : 0x00 ,
2783
+ keys : [ 0x16 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2784
+ } ,
2785
+ UsbBootKeyboardReport {
2786
+ modifiers : 0x00 ,
2787
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2788
+ } ,
2789
+ UsbBootKeyboardReport {
2790
+ modifiers : 0x00 ,
2791
+ keys : [ 0x2C , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2792
+ } ,
2793
+ UsbBootKeyboardReport {
2794
+ modifiers : 0x00 ,
2795
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2796
+ } ,
2797
+ UsbBootKeyboardReport {
2798
+ modifiers : 0x00 ,
2799
+ keys : [ 0x04 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2800
+ } ,
2801
+ UsbBootKeyboardReport {
2802
+ modifiers : 0x00 ,
2803
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2804
+ } ,
2805
+ UsbBootKeyboardReport {
2806
+ modifiers : 0x00 ,
2807
+ keys : [ 0x2C , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2808
+ } ,
2809
+ UsbBootKeyboardReport {
2810
+ modifiers : 0x00 ,
2811
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2812
+ } ,
2813
+ UsbBootKeyboardReport {
2814
+ modifiers : 0x00 ,
2815
+ keys : [ 0x17 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2816
+ } ,
2817
+ UsbBootKeyboardReport {
2818
+ modifiers : 0x00 ,
2819
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2820
+ } ,
2821
+ UsbBootKeyboardReport {
2822
+ modifiers : 0x00 ,
2823
+ keys : [ 0x08 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2824
+ } ,
2825
+ UsbBootKeyboardReport {
2826
+ modifiers : 0x00 ,
2827
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2828
+ } ,
2829
+ UsbBootKeyboardReport {
2830
+ modifiers : 0x00 ,
2831
+ keys : [ 0x16 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2832
+ } ,
2833
+ UsbBootKeyboardReport {
2834
+ modifiers : 0x00 ,
2835
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2836
+ } ,
2837
+ UsbBootKeyboardReport {
2838
+ modifiers : 0x00 ,
2839
+ keys : [ 0x17 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2840
+ } ,
2841
+ UsbBootKeyboardReport {
2842
+ modifiers : 0x00 ,
2843
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2844
+ } ,
2845
+ UsbBootKeyboardReport {
2846
+ modifiers : 0x02 ,
2847
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2848
+ } ,
2849
+ UsbBootKeyboardReport {
2850
+ modifiers : 0x02 ,
2851
+ keys : [ 0x1E , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2852
+ } ,
2853
+ UsbBootKeyboardReport {
2854
+ modifiers : 0x02 ,
2855
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2856
+ } ,
2857
+ UsbBootKeyboardReport {
2858
+ modifiers : 0x00 ,
2859
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2860
+ } ,
2861
+ UsbBootKeyboardReport {
2862
+ modifiers : 0x00 ,
2863
+ keys : [ 0x28 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2864
+ } ,
2865
+ UsbBootKeyboardReport {
2866
+ modifiers : 0x00 ,
2867
+ keys : [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
2868
+ } ,
2869
+ ] ;
2870
+ let mut output = String :: new ( ) ;
2871
+ let mut keyboard = UsbKeyboard :: new ( layouts:: Us104Key , HandleControl :: MapLettersToUnicode ) ;
2872
+ for report in reports. iter ( ) {
2873
+ for ev in keyboard. handle_report ( report) {
2874
+ if let DecodedKey :: Unicode ( ch) = ev {
2875
+ output. push ( ch) ;
2876
+ }
2877
+ }
2878
+ }
2879
+ assert_eq ! ( "Hello this is a test!\n " , output) ;
2880
+ }
2672
2881
}
2673
2882
2674
2883
// ****************************************************************************
0 commit comments