Want to continue with my Script when a counter on screen stops

Asked by Rico Muehle

Hi, I am fairly new to Sikulix and have a problem that I can't find a solution to.

I have a counter on screen that will go up every 1 - 5 seconds and I want my script to observe the counter, click every second on a certain part of the screen until the counter stops going up and then continue with my script.

Thanks in advance.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Amyjackson (amyjackson) said :
#1

Hello,

It sounds like you're looking to create a SikuliX script that observes a counter on your screen and clicks on a specific part of the screen every second until the counter stops increasing. You can achieve this with SikuliX by using image recognition and a loop to continuously check the counter value. Here's a general outline of how to do this:

Import the necessary SikuliX libraries at the beginning of your script:
python
Copy code
import org.sikuli.script.*
Define the image or region where the counter is displayed and the location where you want to click. You can capture these images using SikuliX's built-in capture functionality.
python
Copy code
counterRegion = Region(x, y, width, height) # Define the region where the counter is displayed
clickLocation = Location(x, y) # Define the location where you want to click
Replace x, y, width, and height with the appropriate coordinates and dimensions for your specific application.

Create a loop that continuously checks the counter value:
python
Copy code
while True:
    counterImage = counterRegion.capture() # Capture the current counter image

    # Implement logic to extract the counter value from the captured image.
    # You may need to use text recognition or image comparison to determine the value.

    # Check if the counter has stopped increasing (based on your logic).
    if counter_has_stopped_increasing:
        break # Exit the loop

    click(clickLocation) # Click on the specified location
    wait(1) # Wait for 1 second before the next click
In the loop, you'll need to implement logic to extract the counter value from the captured image. Depending on the counter's appearance, you can use text recognition or image comparison techniques to determine the value.

After the loop exits, your script can continue with the rest of its tasks.
Remember to adjust the script according to your specific application's layout and the logic needed to detect when the counter stops increasing. SikuliX provides various image recognition and manipulation functions to assist you in achieving this task.

If you encounter any specific issues or have more detailed questions, please provide additional information about the counter and its behavior, and I can offer more tailored guidance.

Revision history for this message
Amyjackson (amyjackson) said :
#2
Revision history for this message
Niklas Jørgensen (shortytheman) said (last edit ):
#3

did somone just copy/paste a gpt answer in here? :D

while true:
    region = Region(200,300,10,10) # Capture the region that the counter is within
    number = region.text() #Capture the number
    print(number) print the number from the counter, you might need to use this later
    if waitVanish(number, 6): #So we break if the number hasn't changed for the last 6 seconds in this case.
        break;

this is how i would go about doing it, i tested it and it works fine, lmk if there's any additional questions.

you can modify the region with the numbers, you can also make a region with the IDE and then modify the numbers if need be.

Can you help with this problem?

Provide an answer of your own, or ask Rico Muehle for more information if necessary.

To post a message you must log in.