简体   繁体   English

如何让我的机器人更快地弹奏钢琴曲?

[英]How can I make my bot that plays piano tiles faster?

I scripted a bot to play an online version of piano tiles on the computer.我编写了一个机器人来在计算机上播放在线版本的钢琴块。 It constantly checks the color of the pixels on my screen to see if there is a clickable tile, and if there is, then my bot performs a function to click that spot on the screen.它不断检查我屏幕上像素的颜色,看看是否有可点击的磁贴,如果有,我的机器人就会执行一个功能来点击屏幕上的那个点。 Everything works just fine, but I want to speed up how fast my bot detects pixels and clicks those spots.一切正常,但我想加快我的机器人检测像素和点击这些点的速度。 Any help is appreciated.任何帮助表示赞赏。 The code is below:代码如下:

from pyautogui import *
import pyautogui
import time
import keyboard
import random
import win32api, win32con


def click(x, y):
    win32api.SetCursorPos((x, y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
x_coord = 480
x = 0

while keyboard.is_pressed("q") == False:
    x = x + 1
    print(x)
    if pixel(481, x_coord)[0] == 17:
        click(481, x_coord)
    elif pixel(581, x_coord)[0] == 17:
        click(581, x_coord)
    elif pixel(681, x_coord)[0] == 17:
        click(681, x_coord)
    elif pixel(781, x_coord)[0] == 17:
        click(781, x_coord)

If you need more information regarding the code or the game, please comment and I will try my best to respond.如果您需要有关代码或游戏的更多信息,请发表评论,我会尽力回复。

First of all you have to check for the reaction time.首先,您必须检查反应时间。 This should give you a better view to the problem.这应该可以让您更好地了解问题。 If it is too high like seconds , the problem is probably about how pixels detected .如果它像一样太高,问题可能在于如何检测像素

If the reaction time is good but you want to achieve more you can try other libraries .如果反应时间很好,但你想实现更多,你可以尝试其他库 I couldn't find one right now but I am sure that you can find easily if you use the right keywords .我现在找不到,但我相信如果您使用正确的关键字,您可以轻松找到。 I remember using one that was faster than pyautogui.我记得使用比 pyautogui 更快的一个。

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

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