我正在使用 pyautogui
lib 创建一个自动测试应用程序。我想使用 typewrite
方法将文本输入到表单中。但我的一些输入字符串中含有 unicode 字符。例如:
Næst
根据文档typewrite
只能按单字符键。所以它只是忽略 æ
字符。
您能建议一些简单的解决方法吗?
最佳答案
我知道这个线程已经很旧了,但是为了这个主题,我认为我设法使用 pyperclip 以更简单的方式绕过它。
不要尝试让 pyautogui 输入特殊字符,而是使用 pyperclip 将它们复制到剪贴板,然后使用 pyautogui 粘贴它们。以 Windows 为例:
import pyautogui
import pyperclip
pyperclip.copy("It's leviOsa, not lêvioçÁ!")
pyautogui.hotkey("ctrl", "v")
编辑:
我们可以使其在多个平台上运行,如下所示(感谢@karlo 指出):
import pyautogui
import pyperclip
import platform
def type(text: str):
pyperclip.copy(text)
if platform.system() == "Darwin":
pyautogui.hotkey("command", "v")
else:
pyautogui.hotkey("ctrl", "v")
type("It's leviOsa, not lêvioçÁ!")
关于unicode - 使用 pyautogui 输入 unicode 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33151865/