首页 > 解决方案 > 我正在尝试在循环中使用 pyautogui 向我朋友的 dm 发送垃圾邮件(不要问为什么)

问题描述

我最近安装了 pyautogui,一切似乎都运行良好。我想向我朋友的 dm 发送垃圾邮件,因此使用命令、a、c 和 v。如果我多次键入:pag.hotkey('command','v') 以使其成为重要信息,则一切正常。但是,我尝试使用 for 循环,也尝试过 while 循环,但它似乎没有在循环内执行任何操作。这意味着它将选择我写的要发送垃圾邮件的文本,复制它,但由于粘贴行位于 for 循环中,它不会执行,因此不会一遍又一遍地粘贴它。当我使用 pyautogui 时,所有循环似乎都不起作用。顺便说一句,我使用 PyCharm。

pag.typewrite("jelly",0.1) #enters the text
pag.hotkey('command','a') #selects the text
pag.hotkey('command','c') # copies the text
for i in range(10): #should iterate the line indented 10 times
    pag.hotkey('command', 'v') #pastes the copied text
pag.keyDown('enter') #presses down on enter
pag.keyUp('enter')#releases enter key
#should have sent the phrase 'jelly' ten times in one big text```
**I forgot to include import pyautogui as pag at the top because I accidentally cut it off when I copied and pasted my code**
Someone please help me find a way to use loops with pyautogui, it is very annoying. 

标签: pythonloopspycharmpyautogui

解决方案


pag.typewrite("jelly",0.1) #enters the text
for i in range(10): #should iterate the line indented 10 times
    pag.typewrite("jelly",0.1) #pastes the copied text
pag.keyDown('enter') #presses down on enter
pag.keyUp('enter')#releases enter key

为什么不直接输入短语 jelly 10 次?我看不出有什么区别。


推荐阅读