How to use a self defined hot key to stop a running *.skl

Asked by Pablo Frank

I built a little function:

def clicker():
    n = 0
    while n < 1000:
        click("START.png")
        wait(1)
        click("START.png")
        n = n + 1
        wait(1)

and run the .sikuli containing it, just to try to stop the script using the function below, built according to the answer to the question #172696, and the link given there (http://sikuli.org/docx/globals.html#listening-to-global-hotkeys)
but no matter i type "F1 + ALT + CTRL" (see below), the script does not stop.
REMARK: I need to stop the script, *not* to quit Sikuli because i need to read what's written in "Message" (the tab next to "Test Trace", below the place where the script is written).

the function to stop the .sikuli containing the 'clicker' function:

def stopScript(event):
 quit(Clicker.sikuli)
 Env.addHotkey(Key.F1,KeyModifier.ALT+KeyModifier.CTRL, stopScript)

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

-- 1. running *.skl
I do not understand, why you are talking about a .skl: when running something in the IDE (you want to inspect the message area) one usually have .sikuli.
It is always possible to run the script from command line and see the out put in the command window just as it is produced.

--- 2. your setting of the hot key does not work
If this is all the code in your script, then the hotkey will never be implemented, if stopScript() is not called.
But even if it is called, it will abort with "quit(Clicker.sikuli)", because Sikuli does not know, what quit is.

-- 3. setting a hot key
I understand, that you want to run a script and interrupt it with a self defined hot key (Sikuli already has one to abort a script: Windows: shift-alt-c, Mac: shift-cmd-c), to get back to the IDE window and inspect the message area.

This is how it should be:

**** some-script.sikuli
def stopHandler(event):
    # here we define, what should be done
    # in case the key is pressed
    exit() # we want to exit the running script

Env.addHotkey(Key.F1,KeyModifier.ALT+KeyModifier.CTRL, stopHandler)

n = 0
while n < 1000:
    click("START.png")
    wait(1)
    click("START.png")
    n = n + 1
    wait(1)

Revision history for this message
obaskirt (onur-baskirt) said :
#2

@ RaiMan

As you described alt-shift-c is exit hot key of sikuli. At this point I want to ask two questions.

1- Is there any pause and resume hot keys?

2- If our code fails in the middle of the sikuli script while sikuli script is running (e.g. sikuli can not find an image and exit) can we restart our sikuli script from the failed line? I want to extend this case and make it clear. For example, I have 100 lines of sikuli script. I started my script and it was running but at line 55 my script could not find an image and it stopped or it was running abnormally and I used alt-shift-c to stop sikuli. Then, I fixed line 55 and now I want to re-run my sikuli script from the line 55 not the beginning of my sikuli script. Is it possible?

Thanks in advance for you answers.

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

--1: no, not available

--2: no, not possible with Sikuli IDE. You have to use Eclipse or Netbeans in debugging mode.
One exception: If it is possible to arrange the tested/automated app at the point of failure (image not found), so that the script might go on, you can try these options: http://sikuli.org/docx/region.html#exception-findfailed

Revision history for this message
obaskirt (onur-baskirt) said :
#4

Ok RaiMan, I will check Eclipse/Netbeans and how to use them with Sikuli. But I think the only way to re-run my fixed code from the fixed line in debugging mode. Maybe in the future we can do it in Sikuli IDE. Thank you.

Revision history for this message
Pablo Frank (frank-pablo) said :
#5

Thanks RaiMan, that solved my question.