← Back to team overview

sikuli-driver team mailing list archive

[Question #682734]: Unable to simultaneously listen to global hotkeys and do desktop surveillance

 

New question #682734 on Sikuli:
https://answers.launchpad.net/sikuli/+question/682734

Hi, just getting into SikuliXx 1.1.4,

What I'm trying to achieve is have a global exit hotkey as described under https://sikulix-2014.readthedocs.io/en/latest/interaction.html?highlight=Env.addHotkey#listening-to-global-hotkeys

while at the same time be able to have the script constantly monitor the desktop for images to pop up.

Here's my code thus far:

# hotkey to stop the script
exitScript = False; # global to communicate with main loop
def xHandler(event):
  global exitScript
  exitScript = True # tell main loop that hotkey was pressed
# add the hotkey with its handler
Env.addHotkey("x", KeyModifier.CTRL + KeyModifier.SHIFT, xHandler)

while True:

    if has(Pattern("1.png").similar(0.66)):
        click(Pattern("1.png").similar(0.66))
    if has ("2.png"):   
        click("2.png")
        paste("email@xxxxxxxxx")        
    if has ("3.png"):   
        click()
    
    if (exitScript):
        exit()


both operations have to exist in the same while loop. I tried moving the hotkey exit condition to a different while loop but then whichever while comes last will never be active.
So is there a logic to be able to constantly monitor for desktop activity until I press the global exit hotkey?

Thanks for your help and keep up the good work.


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