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

Python writing character Ä instead off " and ' answear found but not understandable to me please try to explain it

我正在尝试编写一个脚本,写一个脚本,写一个脚本等等。为此,我一直在使用 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')")

我在 Whosebug 中发现了一个带有 的类似问题,但他们说他们有 "Tinkered around" 来让它工作。但我的水平无法理解他们为完成这项工作所做的工作,因此我的问题是:

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

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. 您可以在 _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')