diff --git a/src/machine/usb/descriptor.go b/src/machine/usb/descriptor.go index 3acb2e9a..d57d0bd8 100644 --- a/src/machine/usb/descriptor.go +++ b/src/machine/usb/descriptor.go @@ -67,7 +67,7 @@ var DescriptorCDCHID = Descriptor{ 0x07, 0x05, 0x02, 0x02, 0x40, 0x00, 0x00, 0x07, 0x05, 0x83, 0x02, 0x40, 0x00, 0x00, 0x09, 0x04, 0x02, 0x00, 0x01, 0x03, 0x00, 0x00, 0x00, - 0x09, 0x21, 0x01, 0x01, 0x00, 0x01, 0x22, 0x65, 0x00, + 0x09, 0x21, 0x01, 0x01, 0x00, 0x01, 0x22, 0x7E, 0x00, 0x07, 0x05, 0x84, 0x03, 0x40, 0x00, 0x01, }, HID: map[uint16][]byte{ @@ -80,6 +80,19 @@ var DescriptorCDCHID = Descriptor{ 0x03, 0x15, 0x00, 0x25, 0x01, 0x95, 0x03, 0x75, 0x01, 0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x03, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x09, 0x38, 0x15, 0x81, 0x25, 0x7f, 0x75, 0x08, 0x95, 0x03, 0x81, 0x06, 0xc0, 0xc0, + + 0x05, 0x0C, // Usage Page (Consumer) + 0x09, 0x01, // Usage (Consumer Control) + 0xA1, 0x01, // Collection (Application) + 0x85, 0x03, // Report ID (3) + 0x15, 0x00, // Logical Minimum (0) + 0x26, 0xFF, 0x1F, // Logical Maximum (8191) + 0x19, 0x00, // Usage Minimum (Unassigned) + 0x2A, 0xFF, 0x1F, // Usage Maximum (0x1FFF) + 0x75, 0x10, // Report Size (16) + 0x95, 0x01, // Report Count (1) + 0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) + 0xC0, // End Collection }, }, } diff --git a/src/machine/usb/hid/keyboard/keyboard.go b/src/machine/usb/hid/keyboard/keyboard.go index ce699399..6a5bad64 100644 --- a/src/machine/usb/hid/keyboard/keyboard.go +++ b/src/machine/usb/hid/keyboard/keyboard.go @@ -238,16 +238,26 @@ func (kb *keyboard) sendKey(consumer bool, b []byte) bool { func (kb *keyboard) keyboardSendKeys(consumer bool) bool { var b [9]byte - b[0] = 0x02 - b[1] = kb.mod - b[2] = 0x02 - b[3] = kb.key[0] - b[4] = kb.key[1] - b[5] = kb.key[2] - b[6] = kb.key[3] - b[7] = kb.key[4] - b[8] = kb.key[5] - return kb.sendKey(consumer, b[:]) + + if !consumer { + b[0] = 0x02 // REPORT_ID + b[1] = kb.mod + b[2] = 0x02 + b[3] = kb.key[0] + b[4] = kb.key[1] + b[5] = kb.key[2] + b[6] = kb.key[3] + b[7] = kb.key[4] + b[8] = kb.key[5] + return kb.sendKey(consumer, b[:]) + + } else { + b[0] = 0x03 // REPORT_ID + b[1] = uint8(kb.con[0]) + b[2] = uint8((kb.con[0] & 0x0300) >> 8) + + return kb.sendKey(consumer, b[:3]) + } } // Down transmits a key-down event for the given Keycode. diff --git a/src/machine/usb/hid/keyboard/keycode.go b/src/machine/usb/hid/keyboard/keycode.go index 8b26eacc..762f65b9 100644 --- a/src/machine/usb/hid/keyboard/keycode.go +++ b/src/machine/usb/hid/keyboard/keycode.go @@ -77,6 +77,7 @@ const ( KeyModifierRightAlt Keycode = 0x40 | 0xE000 KeyModifierRightGUI Keycode = 0x80 | 0xE000 + // KeySystemXXX is not supported now KeySystemPowerDown Keycode = 0x81 | 0xE200 KeySystemSleep Keycode = 0x82 | 0xE200 KeySystemWakeUp Keycode = 0x83 | 0xE200