为什么我的 Python 机器人无法运行? (PyAutoGUI)
我用 Python 编写了一个机器人,它应该自动播放“Friday Night Funkin”(在应该按下箭头时按下箭头),但由于某种原因它没有执行任何操作。当箭头被按下时,我截取了箭头的屏幕截图,这样如果 python 看到箭头被按下(它看到图像/屏幕截图),它就会按下相应的键。我尝试关闭灰度,但没有成功。有什么办法可以解决这个问题或者以不同的方式实现它吗?我对Python真的很陌生,这是我的第一个代码,如果这是一个愚蠢的问题和问题,我很抱歉。
我的 FNF 版本:https://poki.pl/g/friday-night-funkin
我的图片: https://i.sstatic.net/JxQdl.jpg
我的代码:
from pyautogui import *
import pyautogui
import time
import keyboard
import numpy as np
import random
import win32api, win32con
time.sleep(5)
while keyboard.is_pressed('q') == False:
if pyautogui.locateOnScreen('leftarrow.png', region=(1010, 50, 650, 200), grayscale=False, confidence=0.7) != None:
pyautogui.keyDown('left')
time.sleep(0.1)
pyautogui.keyUp('left')
if pyautogui.locateOnScreen('rightarrow.png', region=(1010, 50, 650, 200), grayscale=False, confidence=0.7) != None:
pyautogui.keyDown('right')
time.sleep(0.1)
pyautogui.keyUp('right')
if pyautogui.locateOnScreen('uparrow.png', region=(1010, 50, 650, 200), grayscale=False, confidence=0.7) != None:
pyautogui.keyDown('up')
time.sleep(0.1)
pyautogui.keyUp('up')
if pyautogui.locateOnScreen('downarrow.png', region=(1010, 50, 650, 200), grayscale=False, confidence=0.7) != None:
pyautogui.keyDown('down')
time.sleep(0.1)
pyautogui.keyUp('down')
I coded a bot in Python that should automatically play Friday Night Funkin' (press the arrows when they are meant to be pressed) but for some reason it doesn't do anything. I took screenshots of the arrows when they are meant to be pressed and I made it so if python sees that the arrow is meant to be pressed (it sees the images/screenshots) it presses the corresponding key. I tried turning greyscale off but it didn't work. Is there any way to fix this or make it in a different way? I'm really new to Python and this is my first code so sorry if it's a stupid problem and question.
My FNF Version: https://poki.pl/g/friday-night-funkin
My images: https://i.sstatic.net/JxQdl.jpg
My code:
from pyautogui import *
import pyautogui
import time
import keyboard
import numpy as np
import random
import win32api, win32con
time.sleep(5)
while keyboard.is_pressed('q') == False:
if pyautogui.locateOnScreen('leftarrow.png', region=(1010, 50, 650, 200), grayscale=False, confidence=0.7) != None:
pyautogui.keyDown('left')
time.sleep(0.1)
pyautogui.keyUp('left')
if pyautogui.locateOnScreen('rightarrow.png', region=(1010, 50, 650, 200), grayscale=False, confidence=0.7) != None:
pyautogui.keyDown('right')
time.sleep(0.1)
pyautogui.keyUp('right')
if pyautogui.locateOnScreen('uparrow.png', region=(1010, 50, 650, 200), grayscale=False, confidence=0.7) != None:
pyautogui.keyDown('up')
time.sleep(0.1)
pyautogui.keyUp('up')
if pyautogui.locateOnScreen('downarrow.png', region=(1010, 50, 650, 200), grayscale=False, confidence=0.7) != None:
pyautogui.keyDown('down')
time.sleep(0.1)
pyautogui.keyUp('down')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许是复制粘贴滞后,但在“if”之前没有缩进,
使用“not None”而不是“!= None”
使用
您的脚本,因为它现在只能作为 python 文件运行,通过控制台命令或导入。
maybe it is copy-paste lag, but there is no indention before "if"
use "not None" instead of "!= None"
use
your script as it now can be run only as python file, through console command or import.