← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #698136]: Two `def` functions, doesn't work, only bottom one works, why

 

Question #698136 on SikuliX changed:
https://answers.launchpad.net/sikuli/+question/698136

    Status: Open => Answered

RaiMan proposed the following answer:
This works for me:

def hk1(evt):
    print "hk1"

def hk2(evt):
    print "hk2"

def hkx(evt):
    print "terminating"
    global running
    running = False

Env.addHotkey("x", KeyModifier.ALT+KeyModifier.CTRL, hkx);

Env.addHotkey("c", KeyModifier.ALT+KeyModifier.CTRL, hk1);

Env.addHotkey("v", KeyModifier.ALT+KeyModifier.CTRL, hk2);

running = True

while running:
    wait(1)

You need something in your script, to keep it active  (here the while
loop) and a hotkey for script termination (here x).

Do not use exit() in a callback def, since this might stop the IDE (but
can be used if the script is run from commandline only).

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for SikuliX.