gpt4 book ai didi

Python 写字符 Ä 而不是 "and ' 找到答案但我无法理解请尝试解释

转载 作者:太空宇宙 更新时间:2023-11-04 04:39:04 24 4
gpt4 key购买 nike

我正在尝试编写一个脚本来编写脚本,编写脚本等等。为此,我一直在使用 pyautogui 模块。问题是,当我尝试打印出字符 "时,它会写入字符 Ä。这是我目前的脚本,我使用的是瑞典语键盘:

import pyautogui
#command + n creates a new file in python it is the same as inputting ctrl + n
pyautogui.hotkey("command","n")
pyautogui.typewrite("import pyautogui \npyautogui.hotkey('command','n')")

我发现了一个类似的问题 answer在 stackoverflow 中,但他们说他们已经“修补”以使其工作。但我的水平无法理解他们为完成这项工作所做的工作,因此我的问题是:

有人可以解释一下如何使用我的瑞典语键盘进行书写吗?

最佳答案

There are lots of Problems with Keyboard Layouts in pyautogui (when not using the default english layout)

您可以尝试以下方法之一:

  1. 如果您使用的是 Windows:Load Keyboard Layout
win32api.LoadKeyboardLayout
int = LoadKeyboardLayout(KLID, Flags)
  1. 你可以tinker around在 _pyautogui_win.py 中
    if key == '\\':
ctypes.windll.user32.keybd_event(0x11, 0, 0, 0) # should be left control
ctypes.windll.user32.keybd_event(0x12, 0, 0, 0) # should be alt
ctypes.windll.user32.keybd_event(0xDB, 0, 0, 0) # should be alt ß
ctypes.windll.user32.keybd_event(0x11, 0, KEYEVENTF_KEYUP, 0)
ctypes.windll.user32.keybd_event(0x12, 0, KEYEVENTF_KEYUP, 0)
ctypes.windll.user32.keybd_event(0xDB, 0, KEYEVENTF_KEYUP, 0)
return
  1. Linux 和 Mac 的另一个解决方案:

在 Mac 和 Linux 中,可以使用十六进制代码输入 unicode 字符。维基百科上有关于此的文章。我正在为 Mac 编写程序,所以我在键盘设置中启用了 Unicode Hex Input 并编写了以下代码:

def type_unicode(word):
for c in word:
c = '%04x' % ord(c)
pyautogui.keyDown('optionleft')
pyautogui.typewrite(c)
pyautogui.keyUp('optionleft')

关于Python 写字符 Ä 而不是 "and ' 找到答案但我无法理解请尝试解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51058922/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com