I want to send modifier keys like shift, alt, ctrl, etc. without any other key. It should be theoretically possible due to the fact that it works for my normal keyboard (tested it with Xoutput and games).
For now I have to send dummy keystrokes like scroll lock (0xCF) to send the modifiers. I'm using Arduino core for the ESP32 with the ESP32S3 Dev Module.
#include "USBHIDKeyboard.h"
USBHIDKeyboard Keyboard;
Keyboard.press(KEY_LEFT_CTRL); Keyboard.write(0xCF); Keyboard.write(0xCF);
delay(1000);
Keyboard.release(KEY_LEFT_CTRL); Keyboard.write(0xCF); Keyboard.write(0xCF);
This works, but it's realy ugly: sometimes the scroll lock LED flashes and in games the settings sometimes see the scroll lock and complain.
Any ideas?
1 Answer 1
You can use Keyboard.pressRaw()
, 0xE0 - 0xE8 should be the modifiers.
size_t USBHIDKeyboard::pressRaw(uint8_t k) {
uint8_t i;
if (k >= 0xE0 && k < 0xE8) {
// it's a modifier key
_keyReport.modifiers |= (1<<(k-0x80));
} else if (k && k < 0xA5) {
// Add k to the key report only if it's not already present
// and if there is an empty slot.
if (_keyReport.keys[0] != k && _keyReport.keys[1] != k && _keyReport.keys[2] != k && _keyReport.keys[3] != k && _keyReport.keys[4] != k && _keyReport.keys[5] != k) {
for (i=0; i<6; i++) {
if (_keyReport.keys[i] == 0x00) {
_keyReport.keys[i] = k;
break;
}
}
if (i == 6) {
return 0;
}
}
} else {
// not a modifier and not a key
return 0;
}
sendReport(&_keyReport);
return 1;
}