doubleClick() vs region.doubleClick()

Asked by Ador Juan Cruz

trying to optimize my code.
whats the difference between calling keyboard or mouse calls between generic screen and region mouse calls
is there a performance hit ?
e.g.
   doubleClick()
    vs
  myRegion.doubleClick()

sometimes I get lazy and on some of my code I just do
   if myRegion.exists(myPattern,0):
            doubleClick(myRegion.getLastMatch())

Question information

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

unqualified calls like click(), doubleClick(), ... always have SCREEN as region (a convenience for the IDE scripter - SCREEN is a "constant" Screen object for Screen(0) (primary screen)).

If the used action includes an implicit search (click(some_image)) the time consumed depends on the size of the region (SCREEN in this case).

As a general recommendation for speed, accuracy and robustness, one should restrict the search region as much as possible:
restricted_area.action(some_image)

If you give as parameter a Match, Region or Location object to an action like click (as doubleClick(myRegion.getLastMatch()) in your case), the qualifying region (SCREEN.doubleClick(myRegion.getLastMatch()) in your case) does not matter (which is some conceptional oddity in the API).

BTW:
if myRegion.exists(myPattern,0: action(myRegion.getLastMatch())

is recommended anyway, since it avoids an unnecessary second search as with
if myRegion.exists(myPattern,0): action(myPattern)

The upcoming new version will have a shortcut for that:
if myRegion.exists(myPattern,0): myRegion.action()
action() without any parameter will act on the lastMatch of the qualifying region or on its center, if there is no lastMatch.

Revision history for this message
Ador Juan Cruz (ajuan7101) said :
#2

Thanks for the answers.
So there really isnt any difference between calling
  if myRegion.exists(myPattern,0):
            doubleClick(myRegion.getLastMatch())
vs
  if myRegion.exists(myPattern,0):
            myRegion.doubleClick(myRegion.getLastMatch())

Revision history for this message
Ador Juan Cruz (ajuan7101) said :
#3

Thanks RaiMan, that solved my question.