Translate keyboard layout with python

◇◆丶佛笑我妖孽 提交于 2019-12-24 06:45:54

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/45039486/translate-keyboard-layout-with-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!