Ctrl with USBHIDKeyboard.h library

Hello,

Merry Christmas and a happy new year. So I have kind of an odd one. I am using a AZERTY keyboard and a Arduino nano ESP32. I found out that the characters aren't the ones that the examples says. So I made an Excel file of it: |Column 1 | Column 2 | Column 3 | Column 4|

HEX DEC button Shift?
0x00 1 \ no
0x01 2 \ no
0x02 3 \ no
0x03 4 \ no
0x04 5 \ no
0x05 6 \ no
0x06 7 \ no
0x07 8 \ no
0x08 9 backspace no
0x09 10 tab no
0x0a 11 enter no
0x0b 12 \ no
0x0c 13 \ no
0x0d 14 \ no
0x0e 15 \ no
0x0f 16 \ no
0x10 17 \ no
0x10 18 \ no
0x11 19 \ no
0x12 20 \ no
0x13 21 \ no
0x14 22 \ no
0x15 23 \ no
0x16 24 \ no
0x17 25 \ no
0x18 26 \ no
0x19 27 \ no
0x1a 28 \ no
0x1b 29 \ no
0x1c 30 \ no
0x1d 31 \ no
0x1e 32 \ no
0x1f 33 \ no
0x20 34 space no
0x21 35 1 yes
0x22 36 % yes
0x23 37 3 yes
0x24 38 4 yes
0x25 39 5 yes
0x26 40 7 yes
0x27 41 ù no
0x28 42 9 yes
0x29 43 0 yes
0x2a 44 8 yes
0x2b 45 shift yes
0x2c 46 ; no
0x2d 47 ) no
0x2e 48 : no
0x2f 49 - no
0x30 50 à no
0x31 51 & no
0x32 52 é no
0x33 53 no
0xa9 171 ' no
0xaa 172 ( no
0xab 173 - no
0xac 174 è no
0xad 175 _ no
0xae 176 ç no
0xaf 177 à no
0xb0 178 enter no
0xb1 179 esc no
0xb2 180 backspace no
0xb3 181 tab no
0xb4 182 space no
0xb5 183 ) no
0xb6 184 \ no
0xb7 185 ^ no
0xb8 186 $ no
0xb9 187 * no
0xba 188 * no
0xbb 189 m no
0xbc 190 ù no
0xbd 191 ² no
0xbe 192 ; no
0xbf 193 : no
0xc0 194 = no
0xc1 195 shiftlock no
0xc2 196 F1 no
0xc3 197 F2 no
0xc4 198 F3 no
0xc5 199 F4 no
0xc6 200 F5 no
0xc7 201 F6 no
0xc8 202 F7 no
0xc9 203 F8 no
0xca 204 F9 no
0xcb 205 F10 no
0xcc 206 F11 no
0xcd 207 F12 no
0xce 208 printscreen no
0xcf 209 break no
0xd0 210 pause no
0xd1 211 insert no
0xd2 212 begin no
0xd3 213 page up no
0xd4 214 suppr no
0xd5 215 end no
0xd6 216 page down no
0xd7 217 arrow right no
0xd8 218 arrow left no
0xd9 219 arrow down no
0xda 220 arrow up no
0xdb 221 numlock no
0xdc 222 / no
0xdd 223 * no
0xde 224 - no
0xdf 225 + no
0xe0 226 enter no
0xe1 227 \ no
0xe2 228 \ no
0xe3 229 \ no
0xe4 230 \ no
0xe5 231 \ no
0xe6 232 \ no
0xe7 233 \ no
0xe8 234 \ no
0xe9 235 \ no
0xea 236 \ no
0xeb 237 \ no
0xec 238 < no
0xed 239 doc no
0xee 240 \ no
0xef 241 \ no
0xf0 242 \ no
0xf1 243 \ no
0xf2 244 \ no
0xf3 245 \ no
0xf4 246 \ no
0xf5 247 \ no
0xf6 248 \ no
0xf7 249 \ no
0xf8 250 \ no
0xf9 251 \ no
0xfa 252 \ no
0xfb 253 \ no
0xfc 254 \ no
0xfd 255 \ no
0xfe 256 \ no
0xff 257 \ no

There is in the whole table no ctrl at all. And (this is less important) there is also not one windows or alt code.

I have read the library code, and there it says to use the Keyboard.press(KEY_LEFT_CTRL); command. It is the HEX code 0x80, but if you look at the table it is nothing. So it's not that.

I have read thousands of forums, but it is still possible that I missed the one with the solution. So if there is, could you please send a URL?

Does anybody know a solution for this problem?

Thanks,

Siebe

Anybody please?

Hi @siebe. The Arduino ESP32 Boards platform is a fork of the "esp32" boards platform. I see the developers of the esp32 platform have recently made several bug fixes/enhancements to the library, which might be relevant:

Those changes are not present in the Arduino ESP32 Boards platform because it is based on an older version of the esp32 platform.

The esp32 platform does have support for the Nano ESP32 board (though its support is not validated by Arduino so we do recommend the average user to use the Arduino ESP32 Boards platform instead). If you like, you can give it a try to see if the Ctrl emulation will work as you expect with the latest version of the library. Follow the installation instructions here:

https://docs.espressif.com/projects/arduino-esp32/en/latest/installing.html#installing-using-arduino-ide

Make sure you install the latest version 3.1.0 of the platform instead of an older version (e.g., 3.0.7), as the second change I linked above is only available from that version.

After you install the platform, select Tools > Board > esp32 > Arduino Nano ESP32 from the Arduino IDE menus and then upload the test sketch to your board again. That will cause the latest version of the library to be used.

When you want to go back to using the official platform, select Tools > Board > Arduino ESP32 Boards > Arduino Nano ESP32 from the Arduino IDE menus.

1 Like

Thank you very much for your solution, but I don't think this is the problem. I am working in the Arduino cloud.

I do. If I configure my keyboard layout as "French (Standard, AZERTY)" and upload this sketch to my Nano ESP32 board from Arduino Cloud Editor:

#include <USB.h>
#include <USBHIDKeyboard.h>
USBHIDKeyboard Keyboard;

const int enablePin = 2;

void setup() {
  pinMode(enablePin, INPUT_PULLUP);
  Keyboard.begin();
  USB.begin();
}

void loop() {
  if (digitalRead(enablePin) == LOW) {
    Keyboard.press(KEY_LEFT_CTRL);
    delay(1000);
    Keyboard.releaseAll();
    delay(1000);
  }
}

Then when I connect pin 2 to GND, I can see that there are no keypresses.

I'm using this to check for keypresses:

https://codepen.io/QDeltaE/pen/PjXWZr

However, if I then select the Arduino Nano ESP32 board from the "esp32" boards platform version 3.1.0 in Arduino IDE and upload the exact same sketch to the board, then I see the expected keypresses.

Version 2.0.17 of the "esp32" boards platform is installed on the Arduino Cloud servers, so you won't have the bug fix when using Arduino Cloud. Unfortunately I don't know how to fix the bug when using Arduino Cloud.

1 Like

That's my problem.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.