一:鍵盤
? ? ? ? 1:鍵盤的hid描述符如下,數據的輸入斷點為中斷方式,當有鍵盤敲擊事件時,會上報長度為8字節(jié)的數據描述符,描述符共有8字節(jié)的輸入報告和1字節(jié)的輸出報告。
????????0x05,0x01,// Global Generic Desktop
????????0x09,0x06,// Local KeyBoard
????????0xA1,0x01,// Main app collection
????????0x05,0x07,// Global KeyBoard
????????//第1字節(jié)
????????0x19,0xe0,// Local Usage Min (KeyBoard LeftControl)
????????0x29,0xe7,// Local Usage Max (KeyBoard Right GUI)
????????0x15,0x00,// Global Logical Min
????????0x25,0x01,// Global Logical Max
????????0x95,0x08,// Global ReportCount
????????0x75,0x01,// Global ReportSize
????????0x81,0x02,// Main Input(Data,Var,Abs)
????????//第2字節(jié)
????????0x95,0x01,// Global ReportCount
????????0x75,0x08,// Global ReportSize
????????0x81,0x03,// Main Input(Cnst,Var,Abs)
????????//第3-8字節(jié)
????????0x95,0x06,// Global ReportCount
????????0x75,0x08,// Global ReportSize
????????0x15,0x00,// Global Logical Min
????????0x26,0xff,0x00,//Global Logical Max
????????0x19,0x00,// Local Usage Min
????????0x29,0x65,// Local Usage Max
????????0x81,0x00,// Main Output(Data,Ary,Abs)
????????//1字節(jié)輸出報告
????????0x15,0x00,// Global Logical Min
????????0x25,0x01,// Global Logical Max
????????0x95,0x05,// Global ReportCount
????????0x75,0x01,// Global ReportSize
????????0x05,0x08,// Global LED
????????0x19,0x01,// Local Usage Min
????????0x29,0x05,// Local Usage Max
????????0x91,0x02,// Main Output(Data,Var,Abs)
????????//補足上面變成1個字節(jié)
????????0x95,0x01,// Global ReportCount
????????0x75,0x03,// Global ReportSize
????????0x91,0x03,// Main Output(Cnst,Var,Abs)
????????0xc0? ????// Main End collection
2:1字節(jié)的輸出報告
? ? ? ? 如果不給鍵盤配置OUT端點,那么鍵盤的1字節(jié)輸出報告將由控制端點的SetReport進行傳輸。這1個字節(jié)總共用了5bit和3bit常量來補足1個字節(jié)。5bits用來點亮特殊鍵盤上的led燈,比如鍵盤的大小寫,數字鍵等。
3:8字節(jié)的輸入報告
? ? ? ? BYTE? ? ? ? bit7? ? ? ? bit6? ? ? ? ?bit5? ? ? ? ?bit4? ? ? ? ?bit3? ? ? ? bit2? ? ? ? bit1? ? ? ? bit0
? ? ? ? ? ?0? ? ? ? ? ?r-gui? ? ? ? r-alt?? ? ? r-shitf? ? ? ?r-ctrl? ? ? ? l-gui? ? ? ?l-alt? ? ? ?l-shift? ? ? l-ctrl
? ? ? ? ? ?1? ? ? ? ? reserved
? ? ? ? ? ?2? ? ? ? ? keyboard page usage
? ? ? ? ? ?3? ? ? ? ? keyboard page usage
? ? ? ? ? ?4? ? ? ? ? keyboard page usage
? ? ? ? ? ?5? ? ? ? ? keyboard page usage
? ? ? ? ? ?6? ? ? ? ? keyboard page usage
? ? ? ? ? ?7? ? ? ? ? keyboard page usage
? ? ? ? BYTE0 各bit表示足有GUI(win),Alt,Shift,Ctrl鍵是否按下,按下為1。
? ? ? ? BYTE1 保留
? ? ? ? BYTE2-7 表示此時按下的其他所有鍵盤按鍵的鍵碼,從低到高填充,沒按就是0x00.如果同時按下的鍵超過允許,則顯示0xff。
????????keyboard page usage 定義如下:
? ? ? ? #define ? ? ? ?KB_ERROR ? ? ? ? ? ?0x01
? ? ? ? #define ? ? ? ?KB_A ? ? ? ? ? ? ? ?0x04
? ? ? ? #define ? ? ? ?KB_B ? ? ? ? ? ? ? ?0x05
? ? ? ? #define ? ? ? ?KB_C ? ? ? ? ? ? ? ?0x06
? ? ? ? #define ? ? ? ?KB_D ? ? ? ? ? ? ? ?0x07
? ? ? ? #define ? ? ? ?KB_E ? ? ? ? ? ? ? ?0x08
? ? ? ? #define ? ? ? ?KB_F ? ? ? ? ? ? ? ?0x09
? ? ? ? #define ? ? ? ?KB_G ? ? ? ? ? ? ? ?0x0A
? ? ? ? #define ? ? ? ?KB_H ? ? ? ? ? ? ? ?0x0B
? ? ? ? #define ? ? ? ?KB_I ? ? ? ? ? ? ? ?0x0C
? ? ? ? #define ? ? ? ?KB_J ? ? ? ? ? ? ? ?0x0D
? ? ? ? #define ? ? ? ?KB_K ? ? ? ? ? ? ? ?0x0E
? ? ? ? #define ? ? ? ?KB_L ? ? ? ? ? ? ? ?0x0F
? ? ? ? #define ? ? ? ?KB_M ? ? ? ? ? ? ? ?0x10
? ? ? ? #define ? ? ? ?KB_N ? ? ? ? ? ? ? ?0x11
? ? ? ? #define ? ? ? ?KB_O ? ? ? ? ? ? ? ?0x12
? ? ? ? #define ? ? ? ?KB_P ? ? ? ? ? ? ? ?0x13
? ? ? ? #define ? ? ? ?KB_Q ? ? ? ? ? ? ? ?0x14
? ? ? ? #define ? ? ? ?KB_R ? ? ? ? ? ? ? ?0x15
? ? ? ? #define ? ? ? ?KB_S ? ? ? ? ? ? ? ?0x16
? ? ? ? #define ? ? ? ?KB_T ? ? ? ? ? ? ? ?0x17
? ? ? ? #define ? ? ? ?KB_U ? ? ? ? ? ? ? ?0x18
? ? ? ? #define ? ? ? ?KB_V ? ? ? ? ? ? ? ?0x19
? ? ? ? #define ? ? ? ?KB_W ? ? ? ? ? ? ? ?0x1A
? ? ? ? #define ? ? ? ?KB_X ? ? ? ? ? ? ? ?0x1B
? ? ? ? #define ? ? ? ?KB_Y ? ? ? ? ? ? ? ?0x1C
? ? ? ? #define ? ? ? ?KB_Z ? ? ? ? ? ? ? ?0x1D
? ? ? ? #define ? ? ? ?KB_1 ? ? ? ? ? ? ? ?0x1E
? ? ? ? #define ? ? ? ?KB_2 ? ? ? ? ? ? ? ?0x1F
? ? ? ? #define ? ? ? ?KB_3 ? ? ? ? ? ? ? ?0x20
? ? ? ? #define ? ? ? ?KB_4 ? ? ? ? ? ? ? ?0x21
? ? ? ? #define ? ? ? ?KB_5 ? ? ? ? ? ? ? ?0x22
? ? ? ? #define ? ? ? ?KB_6 ? ? ? ? ? ? ? ?0x23
? ? ? ? #define ? ? ? ?KB_7 ? ? ? ? ? ? ? ?0x24
? ? ? ? #define ? ? ? ?KB_8 ? ? ? ? ? ? ? ?0x25
? ? ? ? #define ? ? ? ?KB_9 ? ? ? ? ? ? ? ?0x26
? ? ? ? #define ? ? ? ?KB_0 ? ? ? ? ? ? ? ?0x27
? ? ? ? #define ? ? ? ?KB_ENTER ? ? ? ? ? ?0x28
? ? ? ? #define ? ? ? ?KB_ESC ? ? ? ? ? ? ? ?0x29
? ? ? ? #define ? ? ? ?KB_BACKSPACE ? ? ? ?0x2A
? ? ? ? #define ? ? ? ?KB_TAB ? ? ? ? ? ? ? ?0x2B
? ? ? ? #define ? ? ? ?KB_SPACE ? ? ? ? ? ?0x2C
? ? ? ? #define ? ? ? ?KB_MIUS ? ? ? ? ? ? ? ?0x2D ? ?//-_
? ? ? ? #define ? ? ? ?KB_EQUAL ? ? ? ? ? ?0x2E ? ?//=+
? ? ? ? #define ? ? ? ?KB_LSQUBRACKET ? ? ? ?0x2F ? ?//[{
? ? ? ? #define ? ? ? ?KB_RSQUBRACKET ? ? ? ?0x30 ? ?//]}
? ? ? ? #define ? ? ? ?KB_BACKSLASH ? ? ? ?0x31 ? ?//\|
? ? ? ? #define ? ? ? ?KB_SEMICOLON ? ? ? ?0x33 ? ?//;:
? ? ? ? #define ? ? ? ?KB_APOSTROPHE ? ? ? ?0x34 ? ?//'"
? ? ? ? #define ? ? ? ?KB_TILDE ? ? ? ? ? ?0x35 ? ?//`~
? ? ? ? #define ? ? ? ?KB_COMMA ? ? ? ? ? ?0x36 ? ?//,<
? ? ? ? #define ? ? ? ?KB_FULLSTOP ? ? ? ? ? ?0x37 ? ?//.>
? ? ? ? #define ? ? ? ?KB_SLASH ? ? ? ? ? ?0x38 ? ?///?
? ? ? ? #define ? ? ? ?KB_CAPSLOCK ? ? ? ? ? ?0x39 ?
? ? ? ? #define ? ? ? ?KB_F1 ? ? ? ? ? ? ? ?0x3A
? ? ? ? #define ? ? ? ?KB_F2 ? ? ? ? ? ? ? ?0x3B
? ? ? ? #define ? ? ? ?KB_F3 ? ? ? ? ? ? ? ?0x3C
? ? ? ? #define ? ? ? ?KB_F4 ? ? ? ? ? ? ? ?0x3D
? ? ? ? #define ? ? ? ?KB_F5 ? ? ? ? ? ? ? ?0x3E
? ? ? ? #define ? ? ? ?KB_F6 ? ? ? ? ? ? ? ?0x3F
? ? ? ? #define ? ? ? ?KB_F7 ? ? ? ? ? ? ? ?0x40
? ? ? ? #define ? ? ? ?KB_F8 ? ? ? ? ? ? ? ?0x41
? ? ? ? #define ? ? ? ?KB_F9 ? ? ? ? ? ? ? ?0x42
? ? ? ? #define ? ? ? ?KB_F10 ? ? ? ? ? ? ? ?0x43
? ? ? ? #define ? ? ? ?KB_F11 ? ? ? ? ? ? ? ?0x44
? ? ? ? #define ? ? ? ?KB_F12 ? ? ? ? ? ? ? ?0x45
? ? ? ? #define ? ? ? ?KB_PRTSCR ? ? ? ? ? ?0x46
? ? ? ? #define ? ? ? ?KB_SCOLLLOCK ? ? ? ?0x47
? ? ? ? #define ? ? ? ?KB_PAUSE ? ? ? ? ? ?0x48
? ? ? ? #define ? ? ? ?KB_INSERT ? ? ? ? ? ?0x49
? ? ? ? #define ? ? ? ?KB_HOME ? ? ? ? ? ? ? ?0x4A
? ? ? ? #define ? ? ? ?KB_PAGEUP ? ? ? ? ? ?0x4B
? ? ? ? #define ? ? ? ?KB_DELETE ? ? ? ? ? ?0x4C
? ? ? ? #define ? ? ? ?KB_END ? ? ? ? ? ? ? ?0x4D
? ? ? ? #define ? ? ? ?KB_PAGEDOWN ? ? ? ? ? ?0x4E
? ? ? ? #define ? ? ? ?KB_RARROW ? ? ? ? ? ?0x4F
? ? ? ? #define ? ? ? ?KB_LARROW ? ? ? ? ? ?0x50
? ? ? ? #define ? ? ? ?KB_DARROW ? ? ? ? ? ?0x51
? ? ? ? #define ? ? ? ?KB_UARROW ? ? ? ? ? ?0x52
? ? ? ? #define ? ? ? ?KB_NUMLOCK ? ? ? ? ? ?0x53
? ? ? ? #define ? ? ? ?KB_PAD_DIV ? ? ? ? ? ?0x54 ? ?///
? ? ? ? #define ? ? ? ?KB_PAD_MUL ? ? ? ? ? ?0x55 ? ?//*
? ? ? ? #define ? ? ? ?KB_PAD_MINUS ? ? ? ?0x56 ? ?//-
? ? ? ? #define ? ? ? ?KB_PAD_PLUS ? ? ? ? ? 0x57 ? ?//+
? ? ? ? #define ? ? ? ?KB_PAD_ENTER ? ? ? ?0x58
? ? ? ? #define ? ? ? ?KB_PAD_1 ? ? ? ? ? ?0x59
? ? ? ? #define ? ? ? ?KB_PAD_2 ? ? ? ? ? ?0x5A
? ? ? ? #define ? ? ? ?KB_PAD_3 ? ? ? ? ? ?0x5B
? ? ? ? #define ? ? ? ?KB_PAD_4 ? ? ? ? ? ?0x5C
? ? ? ? #define ? ? ? ?KB_PAD_5 ? ? ? ? ? ?0x5D
? ? ? ? #define ? ? ? ?KB_PAD_6 ? ? ? ? ? ?0x5E
? ? ? ? #define ? ? ? ?KB_PAD_7 ? ? ? ? ? ?0x5F
? ? ? ? #define ? ? ? ?KB_PAD_8 ? ? ? ? ? ?0x60
? ? ? ? #define ? ? ? ?KB_PAD_9 ? ? ? ? ? ?0x61
? ? ? ? #define ? ? ? ?KB_PAD_0 ? ? ? ? ? ?0x62
? ? ? ? #define ? ? ? ?KB_PAD_DEL ? ? ? ? ? 0x63
? ? ? ? #define ? ? ? ?KB_APPLICATION ? ? ? ?0x65 ? ?//RWin右邊鍵
二:鼠標
? ? ? ? 1:鼠標描述符如下
? ? ? ? 0x05,0x01, // Global Generic Desktop
? ? ? ? 0x09,0x02, // Local Mouse
? ? ? ? 0xa1,0x01, // Main app collection
? ? ? ? 0x09,0x01, // Local Pointer
? ? ? ? 0xa1,0x00, // Main phy collection
? ? ? ? 0x95,0x03, // Global ReportCount
? ? ? ? 0x75,0x01, // Global ReportSize
? ? ? ? 0x05,0x09, // Global Button
? ? ? ? 0x19,0x01, // Local Usage Min
? ? ? ? 0x29,0x03, // Local Usage Max
? ? ? ? 0x15,0x00, // Global Logical Min
? ? ? ? 0x25,0x01, // Global Logical Max
? ? ? ? 0x81,0x02, // Main Input(Data,Var,Abs)
? ? ? ? 0x95,0x01, // Global ReportCount
? ? ? ? 0x75,0x05, // Global ReportSize
? ? ? ? 0x81,0x03, // Main Input(Cnsr,Var,Abs)
? ? ? ? 0x95,0x03,0x75,0x08, // Global ReportCount Global ReportSize
? ? ? ? 0x05,0x01, // Global Generic Desktip
? ? ? ? 0x09,0x30, // Local X
? ? ? ? 0x09,0x31, // Local Y
? ? ? ? 0x09,0x38, // Locak Wheel
? ? ? ? 0x15,0x81, // Global Logical Min
? ? ? ? 0x25,0x7f, // Global Logical Max
? ? ? ? 0x81,0x06, // Main Input(Data,Var,Rel)
? ? ? ? 0xc0, ? ? ?// Main End collection
????????鼠標發(fā)送給PC的數據每次4個字節(jié)。
????????BYTE1字節(jié):
????????bit7~3:補充的常數,無意義,這里為0即可
????????bit2: 1表示中鍵按下
????????bit1: 1表示右鍵按下 0表示右鍵抬起
????????bit0: 1表示左鍵按下 0表示左鍵抬起
????????BYTE2 — X坐標變化量,與byte的bit4組成9位符號數,負數表示向左移,正數表右移。用補碼表示變化量
????????BYTE3 — Y坐標變化量,與byte的bit5組成9位符號數,負數表示向下移,正數表上移。用補碼表示變化量
????????BYTE4 — 滾輪變化。0x01(1)表示滾輪向前滾動一格;0xFF(-1)表示滾輪向后滾動一格;0x80(-0)是個中間值,不滾動
? ? ? ? 實際測試:
????????BYTE2 X坐標變化量,當BYTE1的bit4為0的時候,0x01~0x7F為向左移動,0x81~0xFF為向右移動,0x00,0x80為不移動。BYTE1的bit4為1的時候,依舊。試驗數據是跟BYTE1的bit4沒什么關系。
????????BYTE3的變化跟BYTE2的一樣。
因此BYTE2/BYTE3/BYTE4的變化趨勢都是一樣的,中間是分界點,山峰結構。從低到高,再從高到低。
????????文章來源:http://www.zghlxwxcb.cn/news/detail-855444.html
?
文章來源地址http://www.zghlxwxcb.cn/news/detail-855444.html
到了這里,關于USB鍵盤鼠標描述符及數據格式分析的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!