I am trying to write a Python script that can play a simple Android game. In the game, a line of seemingly equally-spaced colored dots are moving from right to left. The dots movement happen in steps and not smoothly. The space between the dots is colored white. The goal is to quickly click the button corresponding to the color of the dot in the middle of the screen.
In my current implementation I use pyautogui to take a screenshot, analyze the the color of the dot in that location, and click the corresponding button. However, I only take screenshots at fixed intervals, but it seems to me that there is some source of randomness in the pacing of the dots preventing me from achieving a high score.
I am looking for a way to write the script such that the arrival of a colored dot to a fixed location on the screen is the trigger to clicking the button. The method should not be time-consuming otherwise I will lose the game.