← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #270104]: Script runs simultaneous with hotkey function

 

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

Karl proposed the following answer:
You can pause and unpause your script with events. See below:

import threading
done = False

def exit_script(event):
    global done
    done = True
    if not my_event.isSet():
        my_event.set()
    

def pause_unpause_script(event):
    if my_event.isSet():
        print('Pausing script...Press Pause to unpause...')
        my_event.clear()
        #popup("Waited ten seconds")
    else:
        print('Unpausing script...Press Pause Lock to pause...')
        my_event.set()

my_event = threading.Event()
my_event.set()

Env.addHotkey(Key.F1, KeyModifier.CTRL, exit_script)
Env.addHotkey(Key.PAUSE, 0, pause_unpause_script)

i="+"
while not done:
    wait(.5)
    my_event.wait()
    print i

Env.removeHotkey(Key.F1, KeyModifier.CTRL)
Env.removeHotkey(Key.PAUSE, 0)

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