如何在 Python PyAutoGUI 中更改键盘 [英] How to Change Keyboard in Python PyAutoGUI

查看:38
本文介绍了如何在 Python PyAutoGUI 中更改键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 PyAutoGUI 打印文本,并且我的键盘设置为 Dvorak,因此每当我打印文本时,都会出现错误的字符.例如,你好世界!"出来的结果是Jdpps <soph!".

当我也将字符串放入变量时,也会发生同样的事情.

有没有办法让它在我输入的时候按字面意思打印出来?

解决方案

所以我最终做的是在我的主目录中创建一个文件 .xkbmap-qwerty,然后运行 ​​os.system("xmodmap ~/.xkbmap-qwerty") 加载密钥,然后它在程序退出时甚至程序运行时都不会影响我的shell.

这是我的文件:

<前><代码>键符 q = q Q键符 w = w W键符 e = e E键符 r = r R键符 t = t T键符 y = y Y键符 u = u U密钥符号 i = i I键符 o = o O键符 p = p Pkeysym 括号左 = 括号左括号左keysym 括号右 = 括号右括号键符 a = a A键符 s = s键符 d = d D键符 f = f F键符 g = g G键符 h = h H键符 j = j J密钥符号 k = k K键符 l = l Lkeysym 分号 = 分号冒号键符quoteright =quoterightquotedbl键符 z = z Z键符 x = x X键符 c = c C键符 v = v V键符 b = b B键符 n = n N键符 m = m Mkeysym 逗号 = 少逗号keysym 周期 = 周期更大keysym 斜线 = 斜线问题键符 1 = 1 感叹号键符 2 = 2 在键符 3 = 3 数字符号键符 4 = 4 美元键符 5 = 5%keysym 6 = 6 asciicircum键符 7 = 7 &符号键符 8 = 8 个星号键符 9 = 9 左括号键符 0 = 0 右下角keysym 减 = 减下划线keysym 等于 = 等于加

I am trying to print out text with PyAutoGUI, and I have my keyboard set to Dvorak, so whenever I print out text, it comes out with incorrect characters. For example, "Hello World!" comes out as "Jdpps <soph!".

The same thing happens when I put the string in a variable too.

Is there a way to make it print out the text literally as I typed it?

解决方案

So what I ended up doing was creating a file .xkbmap-qwerty in my home directory, and then ran os.system("xmodmap ~/.xkbmap-qwerty") to load the keys, and then it didn't affect my shell when the program exited, or even while the program was running.

Here's my file:



    keysym q = q Q
    keysym w = w W
    keysym e = e E
    keysym r = r R
    keysym t = t T
    keysym y = y Y
    keysym u = u U
    keysym i = i I
    keysym o = o O
    keysym p = p P
    keysym bracketleft = bracketleft braceleft
    keysym bracketright = bracketright braceright
    keysym a = a A
    keysym s = s S
    keysym d = d D
    keysym f = f F
    keysym g = g G
    keysym h = h H
    keysym j = j J
    keysym k = k K
    keysym l = l L
    keysym semicolon = semicolon colon
    keysym quoteright = quoteright quotedbl
    keysym z = z Z
    keysym x = x X
    keysym c = c C
    keysym v = v V
    keysym b = b B
    keysym n = n N
    keysym m = m M
    keysym comma = comma less
    keysym period = period greater
    keysym slash = slash question
    keysym 1 = 1 exclam
    keysym 2 = 2 at
    keysym 3 = 3 numbersign
    keysym 4 = 4 dollar
    keysym 5 = 5 percent
    keysym 6 = 6 asciicircum
    keysym 7 = 7 ampersand
    keysym 8 = 8 asterisk
    keysym 9 = 9 parenleft
    keysym 0 = 0 parenright
    keysym minus = minus underscore
    keysym equal = equal plus


这篇关于如何在 Python PyAutoGUI 中更改键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆