python - 我正在尝试在循环中使用 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.
解决方案
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 次?我看不出有什么区别。
推荐阅读
- elasticsearch - 使用自定义分析器时如何查看分析的文本?
- php - 如何在 wordpress 中使用带有联系表 7 的 mailjet
- python - 测试布尔变量
- c++ - 如何在 C++ 中获取自动变量的类型
- python - 使用python抓取html元素的内部标签时出错
- mysql - MySql:按日期计算值的出现次数
- mysql - 从 Spring Boot 获取 MySQL thread_id
- javascript - React Native - 根据动态状态获取json的值
- c++ - 名称包含“.”的 ptree get_value
- javascript - functions.js:1 Uncaught SyntaxError: Unexpected token {