Sending [Del] or [F10] from an ATmega32U4 based Arduino

Hi

When you use an ATmega32U4 based Arduino such as the Leonardo or Micro,
then the Keyboard.print() function can help us send text.

But when we want to send special keys, like

  • KEY_DELETE
  • KEY_ESC
  • KEY_F10
    which functions can be used?

For example,
can these special keys be sent only using the Keyboard.press() function, followed by the Keyboard.releaseAll() function,
or there are other functions that can be used too?
(which don't require a Keyboard.releaseAll() call after them)

Thank you

Keyboard.write(KEY_F10);

That should be equivalent to:

Keyboard.press(KEY_F10);
Keyboard.release(KEY_F10);

Oh
Nice to know that, thank you very much.

So I will use Keyboard.write() in that case, since it's shorter - just 1 command.

Would it be correct to deduce from this that Keyboard.write() can only send 1 key,
and if someone needs a key combination then he must use Keyboard.press() + Keyboard.release()?
(or is there some way to send a combination of more than 1 key, using Keyboard.write()?)

There is a version of .write() that sends multiple keys but it calls the single-key .write() for each key so each is released before the next is pressed. To send a key combination, like Ctrl-Shift-Enter you need:

Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press(KEY_RETURN);
Keyboard.releaseAll();

It would not be hard to write a function that would take an array of bytes and send them as a key combination:

void KeyCombo(const byte *codes)
{
  Keyboard.releaseAll();  // Clear any keys and modifiers left pressed
  for (byte c=*codes; c != '\0'; c=*++codes)
  {
    Keyboard.press(c);
  }
  Keyboard.releaseAll();
}
const byte CtrlShiftEnter[] = {KEY_LEFT_CTRL, KEY_LEFT_SHIFT, KEY_RETURN, 0};
  KeyCombo(CtrlShiftEnter);

Thanks you so much