|
|
@ -124,25 +124,22 @@ int Keyboard_::sendReport(void) {
|
|
|
|
lastKeyReport.modifiers = keyReport.modifiers;
|
|
|
|
lastKeyReport.modifiers = keyReport.modifiers;
|
|
|
|
int returnCode = HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, &lastKeyReport, sizeof(lastKeyReport));
|
|
|
|
int returnCode = HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, &lastKeyReport, sizeof(lastKeyReport));
|
|
|
|
lastKeyReport.modifiers = last_mods;
|
|
|
|
lastKeyReport.modifiers = last_mods;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// If modifiers are being turned off, then we send the new report with the previous modifiers.
|
|
|
|
// If modifiers are being turned off, then we send the new report with the previous modifiers.
|
|
|
|
// We need to do this, at least on Linux 4.17 + Wayland.
|
|
|
|
// We need to do this, at least on Linux 4.17 + Wayland.
|
|
|
|
// Jesse has observed that sending Shift + 3 key up events in the same report
|
|
|
|
// Jesse has observed that sending Shift + 3 key up events in the same report
|
|
|
|
// will sometimes result in a spurious '3' rather than '#', especially when the keys
|
|
|
|
// will sometimes result in a spurious '3' rather than '#', especially when the keys
|
|
|
|
// had been held for a while
|
|
|
|
// had been held for a while
|
|
|
|
|
|
|
|
else if (( (lastKeyReport.modifiers ^ keyReport.modifiers) & lastKeyReport.modifiers)
|
|
|
|
if (( (lastKeyReport.modifiers ^ keyReport.modifiers) & lastKeyReport.modifiers)
|
|
|
|
&& (memcmp(lastKeyReport.keys,keyReport.keys, sizeof(keyReport.keys)))) {
|
|
|
|
&& (memcmp(lastKeyReport.keys,keyReport.keys, sizeof(keyReport.keys)))) {
|
|
|
|
uint8_t mods = keyReport.modifiers;
|
|
|
|
uint8_t mods = keyReport.modifiers;
|
|
|
|
keyReport.modifiers = lastKeyReport.modifiers;
|
|
|
|
keyReport.modifiers = lastKeyReport.modifiers;
|
|
|
|
int returnCode = HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, &keyReport, sizeof(lastKeyReport));
|
|
|
|
int returnCode = HID().SendReport(HID_REPORTID_NKRO_KEYBOARD, &keyReport, sizeof(lastKeyReport));
|
|
|
|
keyReport.modifiers = mods;
|
|
|
|
keyReport.modifiers = mods;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int returnCode = sendReportUnchecked();
|
|
|
|
int returnCode = sendReportUnchecked();
|
|
|
|
if (returnCode > 0)
|
|
|
|
if (returnCode > 0)
|
|
|
|
memcpy(lastKeyReport.allkeys, keyReport.allkeys, sizeof(keyReport));
|
|
|
|
memcpy(lastKeyReport.allkeys, keyReport.allkeys, sizeof(keyReport));
|
|
|
@ -218,14 +215,13 @@ size_t Keyboard_::press(uint8_t k) {
|
|
|
|
uint8_t bit = 1 << (uint8_t(k) % 8);
|
|
|
|
uint8_t bit = 1 << (uint8_t(k) % 8);
|
|
|
|
keyReport.keys[k / 8] |= bit;
|
|
|
|
keyReport.keys[k / 8] |= bit;
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else { // It's a modifier key
|
|
|
|
|
|
|
|
if (k >= HID_KEYBOARD_FIRST_MODIFIER && k <= HID_KEYBOARD_LAST_MODIFIER) {
|
|
|
|
// It's a modifier key
|
|
|
|
|
|
|
|
else if (k >= HID_KEYBOARD_FIRST_MODIFIER && k <= HID_KEYBOARD_LAST_MODIFIER) {
|
|
|
|
|
|
|
|
// Convert key into bitfield (0 - 7)
|
|
|
|
// Convert key into bitfield (0 - 7)
|
|
|
|
k = k - HID_KEYBOARD_FIRST_MODIFIER;
|
|
|
|
k = k - HID_KEYBOARD_FIRST_MODIFIER;
|
|
|
|
keyReport.modifiers |= (1 << k);
|
|
|
|
keyReport.modifiers |= (1 << k);
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// No empty/pressed key was found
|
|
|
|
// No empty/pressed key was found
|
|
|
@ -238,14 +234,13 @@ size_t Keyboard_::release(uint8_t k) {
|
|
|
|
uint8_t bit = 1 << (k % 8);
|
|
|
|
uint8_t bit = 1 << (k % 8);
|
|
|
|
keyReport.keys[k / 8] &= ~bit;
|
|
|
|
keyReport.keys[k / 8] &= ~bit;
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else { // It's a modifier key
|
|
|
|
|
|
|
|
if (k >= HID_KEYBOARD_FIRST_MODIFIER && k <= HID_KEYBOARD_LAST_MODIFIER) {
|
|
|
|
// It's a modifier key
|
|
|
|
|
|
|
|
else if (k >= HID_KEYBOARD_FIRST_MODIFIER && k <= HID_KEYBOARD_LAST_MODIFIER) {
|
|
|
|
|
|
|
|
// Convert key into bitfield (0 - 7)
|
|
|
|
// Convert key into bitfield (0 - 7)
|
|
|
|
k = k - HID_KEYBOARD_FIRST_MODIFIER;
|
|
|
|
k = k - HID_KEYBOARD_FIRST_MODIFIER;
|
|
|
|
keyReport.modifiers &= ~(1 << k);
|
|
|
|
keyReport.modifiers &= ~(1 << k);
|
|
|
|
return 1;
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// No empty/pressed key was found
|
|
|
|
// No empty/pressed key was found
|
|
|
|