I'm using a digispark arduino-compatible device to emulate a keyboard with an US layout (it uses DigiKeyboard.h
as library to do so).
Now,it just takes as input an integer which represent a key and sends it to the computer following the USB keyboard standards, everything fine until this point.
The problem is that I need this device to work with every keyboard layout, my question is: is there a way to "translate" the numeric value representing a character to the numeric value which represent the same character in any other layout using python? Obviously I cannot change the layout via software on the computer.
Example: lets say that in the US layout the character "x" is represented as the number 1. In the ES layout the character "x" is represented as the number 2. I need an hypothetic function that given the number 1 will output the number 2.
EDIT: Had some researches, couldn't find a proper solution, yet the hak5 team has developed something similar for the rubber ducky, you can find useful files on github
In short: it is not possible.
The library doesn't support that, let me elaborate a little further:
I've generated a "lookup table" (using the hak5 files mentioned in the question) which allowed me to check which key + modifiers to use to represent a given character in a given layout (quite of a good piece of software actually); it was a big let down for me to find out that the library supported the "shift" modifiers only (while in other layouts alt-gr is needed). The "keystroke" is coded in the following way: 7-bits are used to represent the ASCII code of the character (obviously it only supports the 7-bit ASCII characters in the US keyboard), while the most significant bit represent whether or not the modifier is used.
TL;DR: DigiKeyboard supports one modifiers only, making it good for US layout (or similar) only.
A quick and dirty workaround it to use this tool here to translate a rubbery ducky script in a digispark one using the tools the hak5 team wrote.