Click after find not fast enough - takes some 10 milliseconds --- no solution

Asked by Charles Sosmena on 2020-07-10

Hi, I'm trying to make a code for a game that clicks immediately after the "image/pattern" appears. My problem is it's too slow, I require about 20-40ms of reaction time.

reg.wait("Get Ready Image",FOREVER)
reg.wait(Pattern("Click Me Image").similar(0.78),FOREVER)
click(reg.getLastMatch())
Settings.MoveMouseDelay = 0.0
Settings.WaitScanRate = 100
Settings.DelayBeforeMouseDown = 0.0

I played this command on https://humanbenchmark.com/tests/reactiontime and I got an average of 60-70ms. Checking on the message box it says about 20-35ms when it clicked. I tried importing the module Vision to speed up sikuli but the error says "Cannot import name Vision".

 Also is changing DelayBeforeMouseDown changes it or is it already the default? Is there a way to make it react faster without upgrading my hardware?

I have tried onChange() commands but I don't get why it still continues to click even though I called stopObserver().
reg.wait("Get Ready Image",FOREVER)
def react(event):
    click(reg)
    wait(0.5)
Settings.MoveMouseDelay = 0.0
Settings.ObserveScanRate = 100
Settings.DelayBeforeMouseDown = 0.0
reg.onAppear(Pattern("Click Me Image").similar(0.78),react)
reg.observe(FOREVER)
reg.stopObserver()

P.S. The game is in Bluestacks and could run offline, would that help?
Thanks in advance!

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2020-07-11
Last query:
2020-07-11
Last reply:
2020-07-11
RaiMan (raimund-hocke) said : #1

1. use SikuliX version 2.0.4

2. in a script at the beginning add:
Settings.MoveMouseDelay = 0.0
Settings.WaitScanRate = 10

nothing else is needed.

3. make the region reg as small as possible

4. create the "Click Me Image"-image with as little background as possible

5. to click:
click(reg.wait(Pattern("Click Me Image"),FOREVER))

Hi thanks for the reply. I followed your instructions and I made the region to a 9x9 pixel and I made the image to as small as I can crop it but it's still the same 60-70ms and the fastest I could get was 59ms.

cycle = 0
def react():
    big_reg.wait("Get Ready Image",FOREVER)
    hover(reg)
    click(small_reg.wait(Pattern("Click Me Image"),FOREVER))
Settings.MoveMouseDelay = 0.0
Settings.WaitScanRate = 10
while cycle !=5:
    react()
    cycle+=1

Btw this is the log from SikuliX IDE:
[log] CLICK on L[900,248]@S(0) (37 msec)
[log] CLICK on L[900,248]@S(0) (22 msec)
[log] CLICK on L[900,248]@S(0) (23 msec)
[log] CLICK on L[900,248]@S(0) (21 msec)
[log] CLICK on L[900,248]@S(0) (37 msec)
[log] CLICK on L[900,248]@S(0) (23 msec)
[log] CLICK on L[900,248]@S(0) (23 msec)
[log] CLICK on L[900,248]@S(0) (22 msec)
[log] CLICK on L[900,248]@S(0) (38 msec)
[log] CLICK on L[900,248]@S(0) (32 msec)

Manfred Hampl (m-hampl) said : #6

Just an idea:
Are you sure that these 60-70 ms are solely caused by the reaction time?
Maybe the numbers include some network transfer time plus calculation time for the results plus ...

Great idea! I'll download an offline reaction time test software and I'll test it there.

Sadly I can't find any reaction time test software that is offline.

RaiMan (raimund-hocke) said : #10

I am sorry, you have to live with that timing currently (no idea whether this can be improved at all).

I made some tests myself with the mentioned benchmark site and got times of some 10 milliseconds best.

I will go deeper into the implementation to eventually find possible improvements.

Thanks for the effort in testing this. I shall wait for future improvements.

Can you send me the code that you used in the benchmark site to get to 10 milliseconds?

Best RaiMan (raimund-hocke) said : #12

I said: ... some 10 milliseconds ;-)

with
Settings.MoveMouseDelay = 0.0
Settings.WaitScanRate = 100
Location(340, 254).click()
img = "img.png" # the C from the word Click!
reg = Region(852,351,70,88) # a small region where the C should appear
reg.wait(img, 10)
reg.click()

I got reaction times around 40 msecs (Windows 10 Pro latest, 64-Bit, Intel Xeon E5-1650 v3)

Using observe/onChange is a bit slower (about 10 msecs).

Thanks RaiMan, that solved my question.

Thank you very much. I think I know the cause of the problem now. It's because of my specs (AMD A8-7650K), it can't process that much. Again, thanks.