When creating an Env.addHotkey, using an import function as the handler causes the hotkey to trigger as soon as you start the script.

Asked by Joshua Noble on 2018-10-18

Using two scripts in conjunction here. I will use scripts 'A' and 'B' as my examples with functions to match:

#######scriptA.py#######
from sikuli import *

def a():
    print ("hello world")

#######scriptB.py#######

import scriptA
from scriptA import a

Env.addHotkey('b',KeyModifier.ALT+KeyModifier.CTRL, a)

---------------------------------------------

The result here is that as soon as you launch script B, the function 'a' will trigger. If you move this function into scriptB.py, then the hotkey works as intended.

Does anyone have any suggestions? RaiMan, you're my only hope!

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Joshua Noble
Solved:
2018-10-18
Last query:
2018-10-18
Last reply:
2018-10-18
RaiMan (raimund-hocke) said : #1

I am sorry, but I cannot reproduce this problem here (version 1.1.4) on Mac.

... but I found a few other oddities with the revised Hotkey feature, that I now have to track down and fix ;-)

BTW: as a best practice to be name-safe:

import testSub
...
Env.addHotkey('b',KeyModifier.ALT+KeyModifier.CTRL, testSub.a)

Joshua Noble (shocknoble) said : #2

Thanks a bunch, I will triple check I am executing this properly. Best of luck with those other oddities!