Until now, I used UWSC exclusively for PC automation work, so I was interested in Python, but I didn't have a chance to learn it, but I thought that I would not start somewhere due to the current situation of UWSC, so I started it the other day Thanks to Sukusta (love live sound social game), I got the motivation to automatically play the MV of the game, so I took this opportunity to start Python.
For the convenience of the content, it is almost about the automation macro of social games using Android emulation such as Nox and Bluestacks.
Windows10 64bit Python3.8 64bit Bluestacks4
I was at a loss with Nox for Android emulation, but I used Bluestacks for Nox because the lip sync is off by about 10 frames.
pip install pyautogui
It seems that it cannot be excluded from automation with Python.
The operation is simply to press the MV button on the screen below and Press the play button at the point where the screen changes. After that, loop until the song is over and the MV button in image 1 is displayed.
Constant declaration part
MAIN_PATH=".\\MVPlay\\"
FILE_TYPE="*.png "
X:int=0
Y:int=1
Main code
coding:utf-8
import pyautogui
import glob
import time
from pydef import*
def counterModeSerial(i:int,maxcount:int):
if i>=maxcount:
return 0
else:
return i+1
def main(files:list,loopmode:int,waittime:int):
i:int=0
while True:
loc=pyautogui.locateCenterOnScreen(files[i])
if not(loc==None):
time.sleep(waittime)
pyautogui.click(loc[X],loc[Y])
i=counterModeSerial(i,len(files)-1)
time.sleep(waittime)
flist=glob.glob(MAIN_PATH+FILE_TYPE)
main(flist,0,0.5)
Crop the image of the component you want to tap and put it in the folder so that it will be executed sequentially. In this case, it will be an image of a MV or a play button. If you create an MVPlay folder and put a png file in it, "Recognize-> Tap-> Next file-> Recognize ... Return to the beginning when the last image is recognized" is repeated in the order sorted by file name. Since the termination process is not included, you need to kill the process from the task manager unless you start it with the debugger.
If you put an image in a folder, it will recognize the image, click it, and transition to the next state, so it seems that it will be enough for 2D social network games as it is.
Except for references and variable declarations, I think it's a good idea to work with about 10 lines of code, and I think it's just said to be simple and powerful. The locateOnScreen function does not support multi-display and only checks the primary display (I managed to replace the work monitor with the secondary), but there were some complaints such as slow image recognition, but overall It was easy to use. Isn't it because the old man thinks it's a little scary to express nesting with indentation, but is there an advantage that readability is improved because clean indentation is forced?
The goal was achieved for the time being, but with this, only one song can be looped, and the mouse cursor and active window are brought when the button is pressed, so we improved things such as sending commands via ADB. I would like to go.
Recommended Posts