← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #272075]: Using multiple hotkeys without popups? Is this possible?

 

Question #272075 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/272075

    Status: Open => Answered

RaiMan proposed the following answer:
ok, I think, I understand your problem.

If you want to run a script, that only implements hotkeys and does
nothing else, then this is a possible generic structure:

shouldRun = True

def handler1(event):
    # do something if the corresponding hotkey is pressed

def handler2(event):
    # do something if the corresponding hotkey is pressed

... more of them if needed

def handlerStop():
    global shouldRun
    shouldRun = False

Env.addHotkey(Key.NUM1,KeyModifier.CTRL, handler1)
Env.addHotkey(Key.NUM2,KeyModifier.CTRL, handler2)

... more of them if needed

Env.addHotkey("x",KeyModifier.CTRL + KeyModifier.ALT, handlerStop) #
press ctrl-alt-x to stop the script

# if you want:
popup("hotkeys are active now - click OK")

while shouldRun: # keep the script alive until the stop key is pressed
    wait(1)

# if you want:
popup("hotkeys will be deactivated after clicking ok")

activated hotkeys are auto-inactivated when the script ends.

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