Testing if something was clicked? (clickable)

Asked by Zachary R

I'm using the guide.clickable module. I want Sikuli to do something after a region is clicked

In my mind this is what I want:
guide.clickable("Random Screenshot.png")
if (this is clicked)
  type("whatever")

Also, how do I keep a sikuli script running until I click something to shut it down? This would be a huge help :D thanks

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
RaiMan (raimund-hocke) said :
#1

--1.

At least the action element clickable works with the current version guide-1.4.2:

from guide import *
clickable("some-image.png")
show()

A clickable element can be named with a second parameter

clickable("some-image.png", "some-image")

and when clicked you can see the effect in the message area (Last clicked: name). The methods to check the last clicked element are not yet implemented though in the Sikuli script API.

So this feature is usable with the restriction, that the script is waiting at the show() for the user to click (without show, the clickable element will not be activated). On top, even if you say show(5), it will currently ignore the timing parameter and wait forever (this is true, if either a dialog() or a clickable() is registered)

--2. this leads to your second question:

In the standard Sikuli API (guide is an extension) currently there is no feature to get a feedback about a click somewhere. We only can react on the visual effects a click has.

So if I need it in a script, I use some image, that is visible all the time in a specific area on the screen. The script stops, when this image is no longer visible.

keep_running = "some-image.png"

while exists(keep_running, 0):
   # your scripting

to stop the script, I simply hide the image keep_running somehow.

--- You might implement it with an

some_region = Region(...) # or any other approach to define the region
some_region.shouldStop = False

def handler(event):
   event.region.shouldStop = True
   event.region.stopObserver()

some_region.onChange(handler)
some_region.observe(FOREVER, background=True)

while not some_region.shouldStop:
   # here goes your scripting

I still think, the exists() is a bit easier. observe() is interesting, if you have more than 2 or 3 events in parallel to observe.

--- if you are interested in more sophistication according parallelism in Sikuli scripts, have a look at Python modules thread and threading (http://docs.python.org/library/thread.html#module-thread) which allows to implement observe()-like features on your own. (do not use subprocess - it makes problems currently).

Can you help with this problem?

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

To post a message you must log in.