用python翻译键盘布局 [英] Translate keyboard layout with python
问题描述
我正在使用digispark arduino兼容设备来模拟具有美国布局的键盘(它使用DigiKeyboard.h
作为库来这样做).
现在,它只是将代表键的整数作为输入,并按照USB键盘标准将其发送到计算机,直到现在一切正常.
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.
问题是我需要此设备与每种键盘布局配合使用,我的问题是:是否有一种方法可以将表示字符的数值转换"为使用任何其他布局中表示相同字符的数值Python?显然,我无法通过计算机上的软件更改布局.
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.
示例:假设在美国布局中,字符"x"表示为数字1.在ES布局中,字符"x"表示为数字2.我需要一个假设函数,给定数字1将输出数字2.
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.
进行了一些研究,找不到合适的解决方案,但是hak5团队已经为橡皮鸭开发了类似的东西,您可以在
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
推荐答案
简而言之:不可能.
该库不支持该功能,让我进一步详细说明:
The library doesn't support that, let me elaborate a little further:
我已经生成了一个查找表"(使用问题中提到的hak5文件),它使我能够检查要使用哪些键+修饰符来表示给定布局中的给定字符(软件);我发现该库仅支持"shift"修饰符(这在其他布局中需要alt-gr)对我来说是一个很大的遗憾. 击键"的编码方式如下:7位用于表示字符的ASCII码(显然,它仅支持美国键盘中的7位ASCII字符),而最高位表示是否使用修饰符.
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仅支持一个修饰符,使其仅适用于美国版式(或类似格式).
TL;DR: DigiKeyboard supports one modifiers only, making it good for US layout (or similar) only.
使用此工具的快速而肮脏的解决方法在此处将橡胶状的鸭子脚本翻译为digispark使用hak5团队编写的工具.
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.
这篇关于用python翻译键盘布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!