简体   繁体   English

pyautogui 不能写@ 符号

[英]pyautogui cannot write the @ symbol

I've been trying to produce the "@" character with pyautogui:我一直在尝试使用 pyautogui 生成“@”字符:

import pyautogui
pyautogui.typewrite("@")
pyautogui.typewrite("\x40")

But I can't seem to make it type a "@" in any way.但我似乎无法以任何方式输入“@”。

My keyboard uses AltGr + 2 to create an "@" symbol, but I haven't been able to make that work either.我的键盘使用AltGr + 2创建一个“@”符号,但我也无法做到这一点。

pyautogui.hotkey('altright','2')

I did not find a way to do it with the write method, but in some scenarios you could work around it by putting the @ on the clipboard and paste it:我没有找到使用write方法的方法,但在某些情况下,您可以通过将@放在剪贴板上并粘贴来解决它:

import pyperclip
pyperclip.copy('@')
pyautogui.hotkey('ctrl', 'v')

use the hotkey function使用热键功能

from pyautogui import hotkey
hotkey("alt","l")

This is what works for me on mac, you will know your windows shortcut to write an @ symbol... ;)这在 mac 上对我有用,你会知道你的 Windows 快捷方式来写一个 @ 符号......;)

Neither of the suggested solutions work for keyboard layouts that isn't the standard US keyboard layout.建议的解决方案均不适用于非标准美式键盘布局的键盘布局。 The problem is that pyautogui doesn't really handle different keyboard layouts that well.问题是 pyautogui 并不能很好地处理不同的键盘布局。 Switching to standard US keyboard layout in your OS should solve any issues with special characters.在您的操作系统中切换到标准美式键盘布局应该可以解决特殊字符的任何问题。

也许您可以尝试更改键盘布局:$ setxkbmap us

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM