我想使用HID将键盘快捷键CMD+SPACE
发送到mac,这会打开Spotlight。所以我需要CMD作为保持键,以及触发快捷键的空间。我该怎么做呢?我正在使用LightBlue bean,它使用HID协议通过蓝牙与mac通信。在其他地方为我工作的一个例子是:
BeanHid.sendKeys("/dnd "); //turn do not disturb off if it is on
BeanHid.sendKeys("\r\n"); //return / newline
lightblue bean的HID类的引用如下:
我猜我需要holdKey
,sendKey
和releaseKey
方法。但我需要的是任何代码都代表cmd和空格。
答案 0 :(得分:1)
Apple“Command”键,Windows“Windows”键和Linux“Super”键均由USB“GUI”键修饰符位表示。
有两个:左GUI和右GUI。空格键只是USB“空格键”的用法。因此,您需要在缓冲区中构建和发送“Left GUI”修饰符+“Spacebar”。
该缓冲区的确切内容取决于您使用的HID报告描述符,但对于以下相当典型的键盘报告描述符:
05 01 (GLOBAL) USAGE_PAGE 0x0001 Generic Desktop Page
09 06 (LOCAL) USAGE 0x00010006 Keyboard (CA=Application Collection)
A1 01 (MAIN) COLLECTION 0x00000001 Application (Usage=0x00010006: Page=Generic Desktop Page, Usage=Keyboard, Type=CA)
05 07 (GLOBAL) USAGE_PAGE 0x0007 Keyboard/Keypad Page
19 E0 (LOCAL) USAGE_MINIMUM 0x000700E0 Keyboard Left Control (DV=Dynamic Value)
29 E7 (LOCAL) USAGE_MAXIMUM 0x000700E7 Keyboard Right GUI (DV=Dynamic Value)
15 00 (GLOBAL) LOGICAL_MINIMUM 0x00 (0)
25 01 (GLOBAL) LOGICAL_MAXIMUM 0x01 (1)
75 01 (GLOBAL) REPORT_SIZE 0x01 (1) Number of bits per field
95 08 (GLOBAL) REPORT_COUNT 0x08 (8) Number of fields
81 02 (MAIN) INPUT 0x00000002 (8 fields x 1 bit) 0=Data 1=Variable 0=Absolute 0=NoWrap 0=Linear 0=PrefState 0=NoNull 0=NonVolatile 0=Bitmap
95 01 (GLOBAL) REPORT_COUNT 0x01 (1) Number of fields
75 08 (GLOBAL) REPORT_SIZE 0x08 (8) Number of bits per field
81 01 (MAIN) INPUT 0x00000001 (1 field x 8 bits) 1=Constant 0=Array 0=Absolute
95 05 (GLOBAL) REPORT_COUNT 0x05 (5) Number of fields
75 01 (GLOBAL) REPORT_SIZE 0x01 (1) Number of bits per field
05 08 (GLOBAL) USAGE_PAGE 0x0008 LED Indicator Page
19 01 (LOCAL) USAGE_MINIMUM 0x00080001 Num Lock (OOC=On/Off Control)
29 05 (LOCAL) USAGE_MAXIMUM 0x00080005 Kana (OOC=On/Off Control)
91 02 (MAIN) OUTPUT 0x00000002 (5 fields x 1 bit) 0=Data 1=Variable 0=Absolute 0=NoWrap 0=Linear 0=PrefState 0=NoNull 0=NonVolatile 0=Bitmap
95 01 (GLOBAL) REPORT_COUNT 0x01 (1) Number of fields
75 03 (GLOBAL) REPORT_SIZE 0x03 (3) Number of bits per field
91 01 (MAIN) OUTPUT 0x00000001 (1 field x 3 bits) 1=Constant 0=Array 0=Absolute 0=NoWrap 0=Linear 0=PrefState 0=NoNull 0=NonVolatile 0=Bitmap
95 06 (GLOBAL) REPORT_COUNT 0x06 (6) Number of fields
75 08 (GLOBAL) REPORT_SIZE 0x08 (8) Number of bits per field
25 65 (GLOBAL) LOGICAL_MAXIMUM 0x65 (101)
05 07 (GLOBAL) USAGE_PAGE 0x0007 Keyboard/Keypad Page
19 00 (LOCAL) USAGE_MINIMUM 0x00070000 Keyboard No event indicated (Sel=Selector)
29 65 (LOCAL) USAGE_MAXIMUM 0x00070065 Keyboard Application (Sel=Selector)
81 00 (MAIN) INPUT 0x00000000 (6 fields x 8 bits) 0=Data 0=Array 0=Absolute
C0 (MAIN) END_COLLECTION Application
...表示LeftGUI修饰符+空格键的缓冲区将是(十六进制):
08 2C
或者,您可以发送RightGUI修饰符+空格键:
80 2C
发送上述其中一项后,您需要通过发送“无按键”缓冲区来指示没有按下任何键:
00 00
值得注意的是,2C是您在HID报告描述符中定义的从USAGE_MINIMUM(0x00)到USAGE_MAXIMUM(0x65)的USAGES数组中的索引(在LOGICAL_MINIMUM 0x00到LOGICAL_MAXIMUM 0x65之间),而不是其中的实际使用代码键盘用法页面(即0x0007002C)。
如果您只想表明空格键已被按下,您可以在HID报告描述符中编码USAGE 0007002C,LOGICAL_MINIMUM 1,LOGICAL_MAXIMUM 1,然后发送:
80 01
...表示当前按下空格键(和GUI修饰符),然后按:
00 00
...表示当前没有按任何键。