Progam slowing down - MouseDown: extended delay

Asked by Shekhar on 2017-12-02

Hi,

I am using sikuli for automating a game. The full code is pretty long but the part that moves / clicks mouse is as follows:-

class click_thread(threading.Thread):
    def __init__(self, reg_to_click):
        threading.Thread.__init__(self)
        self.reg_to_click = reg_to_click
    def run(self):
        click_lock.acquire()
        click_func(self.reg_to_click)
        click_lock.release()

def click_func(reg_to_click):
    while True:
        if auto_mouse == 'go':
            Settings.MoveMouseDelay = 0.1
            Settings.DelayBeforeMouseDown = 0.1
            Settings.ClickDelay = 0.1
            click(reg_to_click.getCenter())
            mouseMove(0,50)
            break
        else:
            print((time.asctime(time.localtime(time.time()))),"click func recd call - waiting 1s")
            wait(1)

click_lock = threading.Lock()

# auto_mouse is a global variable I use to 'pause' mouse actions if reqd by reassigning it from elsewhere

I am using threading to take care of mouse actions. Other functions in the code create a thread instance whenever they need the mouse to click something on the screen in the following way:-

            click_thread_instance = click_thread(reg_to_click)
            click_thread_instance.start()
            click_thread_instance.join()

The program slows down as it runs, resulting in a lot of 'timeouts' in the game i use it on. When i check logs, the most frequent entry seems to be 'MouseDown: extended delay'. I have tried running it both from IDE and the command line. It appears to make no difference to this problem. Any idea what might be causing this and what can be done to rectify it?

My env:-
OS:- Microsoft Windows 10 Home, 64-bit
Java:- Version 8, Update 151, build 1.8.0_151-b12
Sikuli: 1.1.1

Thanks in Advance.
Shekhar

Question information

Language:
English Edit question
Status:
Answered
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2017-12-03
Last reply:
2017-12-04
Shekhar (shekharpr10015) said : #1

I tried to carry out the clicks via a function instead of using multi threading to see if it makes any difference:-

 def click_func(reg_to_click):
  while True:
   if auto_mouse == 'go':
    Settings.MoveMouseDelay = 0.1
    Settings.DelayBeforeMouseDown = 0.1
    Settings.ClickDelay = 0.1
    click(reg_to_click.getCenter())
    mouseMove(0,50)
    break
   else:
    print((time.asctime(time.localtime(time.time()))),"click func recd call - waiting 1s")
    wait(1)

All other functions in the script now call this function to get any clicking done. I am still experiencing the script slowing down gradually. Below are the latest logs:-

[debug] MouseDown: extended delay: 1026
[debug] MouseDown: extended delay: 1176
[debug] MouseDown: extended delay: 1493
[debug] MouseDown: extended delay: 1584
[debug] MouseDown: extended delay: 1658
[debug] MouseDown: extended delay: 3077
[debug] MouseDown: extended delay: 3248
[debug] MouseDown: extended delay: 3394
[debug] MouseDown: extended delay: 5769
[debug] MouseUp: extended delay: 1083
[debug] MouseUp: extended delay: 1094
[debug] MouseUp: extended delay: 1159
[debug] MouseUp: extended delay: 1263
[debug] MouseUp: extended delay: 1394
[debug] MouseUp: extended delay: 2123

Any advise / suggestions would be much appreciated on how to solve this problem.

Thanks

RaiMan (raimund-hocke) said : #2

--- None of these settings make really sense:
            Settings.MoveMouseDelay = 0.1 # 0 would be the value, to switch of the mouse move animation
            Settings.DelayBeforeMouseDown = 0.1 # only relevant for dragDrop, no effect with click
            Settings.ClickDelay = 0.1 # time between down and up for click, standard is 0 which normally works.

--- click using a thread:
not needed with SikuliX 1.1.1+, since internally mouse actions are globally synchronized

--- extended delay
Internally SikuliX uses the Java AWT Robot class to handle mouse actions (Button up/down and move). All higher level mouse actions are composed based on these Robot features.
The error message comes up, when inside the Robot a feature like ButtonDown does not come back after a maximum delay (standard 1 second). This extended delay is not created by any SikuliX feature, but is completely in the layer between the Robot and the system mouse handling.

Since you are automating a game, it might well be, that the game engine is aware of the fact that the mouse actions are non-human and hence interferes the mouse handling with some delay, which seems probable looking at the continuous increase of the delay.

You might try, to implement your central click function using mouseDown() and mouseUp() with surrounding and intermediate short waits, that are randomly generated. This may help, to avoid being detected as a non-human.

Can you help with this problem?

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

To post a message you must log in.