Is click() faster than a normal left click with the mouse?

Asked by Sikuli User

I read in one of the questions posted here (https://answers.launchpad.net/sikuli/+question/102429) that click() will not always work.

I also found myself that in one of my scenarios, click() is doing what is supposed to do (clicking something) but there's nothing happening. However, when I manually use the mouse, my click is OK.

My questions are..is click() different than a left click with the mouse or, what's the difference between a natural left click with the mouse and click()? I would also need to know if for example click() is faster than a natural left click and if it is, how can we make it slower.

Any info and/or directions will be highly appreciated!

Thanks.

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Sikuli User
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Windows or Mac?
Things are very different on these systems, especially with versions before Win7.

My general experience: not the click() itself is the problem, it is the history of the workflow: in words: timing. in many cases I had to add waits() before and sometimes after the actions (e.g. type()) to get them work like expected.

I found it easier to adjust the timing, when never using click(image), but a m=find(image) and then click(m) to have control on the click() as such.

I don't think (but I'm not the developer) that the programmed click() itself differs from the human one, since standard java features are used to perform the mouse click and these are not only used in Sikuli ;-)

I guess with the approach of Sikuli there will always be situations where you have to decide to experiment or to leave it.

Revision history for this message
Sikuli User (hidden-hidden) said :
#2

Windows XP & Windows 7 - Sikuli 9.9 (I can not use version 0.10.1 because of a memory leaking issue)

I have this part in my script:

if wait(image, 2):
   click(image)
   wait(9)

I guess the first line will try to find the image for about 2 seconds and if it finds it will then click it and then wait for about 9 seconds.

The timing should be enough keeping into account that sometimes (very very rarely) it works (and it also works very rarely when using doubleClick()). The problem is that there are times when it doesn't work at all - it just clicks the image but I can not see the bigger image that should comes up. However, I can not use more than 2 seconds for the first wait so I can not test a bigger timing. So, is there any workaround for this? (I'd say no but maybe I am wrong)

Maybe there's a way that we can force the click to stay more on the image we want? Something like when we press the mouse left button and we keep it pressed a little more than we need?

Thanks.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

Ok, I think you have no chance as long as you use 9.9, to test any mouse related features, since they are available only in version 10.

How do you handle the FindFailed exceptions? Switched it off? If the wait() fails, the script should stop normally.

Since I don't know your app, I do not have any further idea, besides switchApp().

Revision history for this message
Sikuli User (hidden-hidden) said :
#4

I have an infinite loop that runs everything and I already use setThrowException() + switchApp(). Everything is working just fine except those clicks.

I had version 0.10.1 installed but my script is throwing some errors in XP as well as Windows 7. I asked about those errors here and Sean answered that there are some memory leaking issues and recommended version 0.9.9.

I have no idea why click() is sometimes working and sometimes not. Will it help if I will use regions so I can avoid checking all screen (2048px x 1152px) for a small image?

Thanks.

Revision history for this message
Sikuli User (hidden-hidden) said :
#5

Here is my script if you want to take a look:

while True:

       setThrowException(False)

       while True:

            switchApp("Mozilla Firefox")

            import random
            pause1 = random.randrange(4,11)
            pause2 = random.randrange(6,9)
            sleep(pause1)
            type("R", KEY_CTRL)
            sleep(pause2)

            if not wait(Pattern("1276488374183.png").similar(0.97).firstN(1),2):
               switchApp("Mozilla Firefox")
               sleep(1)
               type("R", KEY_CTRL)
               sleep(11)
            else:
               pass

            if wait(Pattern("1276475306668.png").exact().firstN(1),2):
               sleep(1)
               doubleClick(Pattern("1276475306668.png").exact().firstN(1)) ## THIS IS THE PROBLEM - NOW I TRIED TO USE DOUBLECLICK BUT IT'S RARELY WORKING AS WITH CLICK()
               sleep(7)
               if wait(Pattern("1276480768427.png").exact().firstN(1),2):
                  sleep(1)
                  click(Pattern("1276480768427.png").exact().firstN(1))
                  sleep(6)
                  if wait(Pattern("1276481018530.png").similar(0.98).firstN(1),2):
                        sleep(1)
                        click(Pattern("1276481018530.png").similar(0.98).firstN(1))
                        sleep(6)

       setThrowException(True)

Revision history for this message
RaiMan (raimund-hocke) said :
#6

4 suggestions:

try:
m = wait(Pattern("1276475306668.png").exact().firstN(1),2)
if m:
   sleep(1)
   click(m)

try:
wait(Pattern("1276475306668.png").similar(0.99),2)
- don't use exact()
- firstN() is not really needed as far as I remember

try (using 0.10.1):
only the critical part, after building up the situation manually (to test the behavior in general)

Using Subregion():
The region handling is buggy in 0.9.9 with calculated subregions and Subregion().click() does not work. I guess it will not improve anything.

Revision history for this message
Sikuli User (hidden-hidden) said :
#7

Thanks!

Revision history for this message
Sikuli User (hidden-hidden) said :
#8

Thanks!