Pressing multiple keys using USBKeyboard library on Arduino Nano 33 BLE Sense

Hi @Klaus_K

I am currently using a Arduino Nano 33 BLE Sense board for my project. I want to press ALT + F4 keys when a signal is triggered. Since this is an mbed_os board, I am using the USBKeyboard.h library. But the issue is, I am able to press only one key at a time. I am not able to press ALT+F4 simultaneously

key.key_code(KEY_F4, KEY_ALT);
delay(100);
key.key_code(KEY_NONE);

where

#define KEY_F4 0x3d

Can someone help me as to how do I get around implementing this?

Thanks and regards

Welcome to the forum.

First, can you please confirm where you got the library from (e.g., provide a link to Github) and post a complete sketch. This will allow others to test this without writing a sketch first and search for the library. Often libraries have the same name for a header file but are different.

If you use this library https://www.arduino.cc/reference/en/language/functions/usb/keyboard/ have a look at the following page

https://www.arduino.cc/reference/en/language/functions/usb/keyboard/keyboardmodifiers

Without testing this, I suspect both your keys are keyboardmodifiers and therefore the library cannot handle your use case. This is just a guess.

Try using ALT and some Letter and see what happens. Or maybe SHIFT. See if you can get small and capital letters printed into a notepad window.

Like a keyboard macro programmable key
Make Your Own Custom Shortcut Buttons With an Arduino (makeuseof.com)

I believe you are looking for keyboard decoder library with "two-key rollover" which will reliably detect only any two keys used simultaneously ; in other words, you can can hold down your ALT on the keyboard and press a + key and be sure that the keypress is correctly detected by the computer. Check if it will support N-Key_Rollover.

If you look at the library source code, the function key_code() allows two parameter. You are only using one.

https://github.com/arduino/ArduinoCore-nRF528x-mbedos/blob/master/libraries/USBHID/USBKeyboard.cpp

bool USBKeyboard::key_code(uint8_t key, uint8_t modifier)

The values for the keys are at the beginning of the file.

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