pyautogui typewrite()仅输出大写

2024-04-26 07:23:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在制作一个脚本,在当前活动的文本字段中键入一些文本。通过研究,我发现了打字机()。但现在我的问题是它似乎只输入大写字母

typewite("hello how are you")
#output
# HELLO HOW ARE YOU

#text.lower() doesnt work either 

我遗漏了什么,或者这是应该的工作方式? 请帮助解决此问题或建议替代方案

顺便说一句,我在ArchLinux上运行python3(许多与pyautogui相关的帖子都有这方面的信息,所以我想这是必要的)

编辑: 它似乎是pyautogui中的第一个typewriter()或任何其他函数将始终使用大写字母。在较低的情况下,将出现后续问题

typewite("hello how are you")
typewite("hello how are you")

#output
# HELLO HOW ARE YOUhello how are you

你明白了


Tags: 文本脚本youhellooutput键入大写字母are
2条回答

pyautogui使用键盘设置。如果你的大写字母锁打开,它会写大写字母。我不能不看Caps Lock是否开启,但问题可能是这个。 顺便说一句,不相关但语言设置对无误键入很重要

编辑:

当caps lock关闭时,此代码工作正常:

import pyautogui as pgui

pgui.press('win')
pgui.typewrite('notepad', 0.2)
pgui.PAUSE = 4
pgui.press('enter')
pgui.typewrite("hello how are you")
pgui.getWindowsWithTitle('Untitled')[0].close()
pgui.press('enter')
pgui.typewrite('foo' + '.txt')
pgui.press('enter')

pyautogui文档说“主键盘函数是write()”,所以您可以尝试使用它来代替typewrite()

https://pyautogui.readthedocs.io/en/latest/keyboard.html#the-write-function

相关问题 更多 >