addHotKey error

Asked by Karl

I am using Windows 10 and SikulixIDE 1.1.0 (2015-10-05_17:07).

-----

def myHandler(event):
    print "inside message"

Key.addHotkey(Key.F2, Key.SHIFT +Key.CTRL, myHandler)
wait(10)
Key.removeHotkey(Key.F2, Key.SHIFT +Key.CTRL)

*****
[error] script [ myHotKey ] stopped with error in line 4
[error] TypeError ( addHotkey(): 2nd arg can't be coerced to int )
-----

def myHandler(event):
    print "inside message"

Key.addHotkey(Key.F2, 0, myHandler)
wait(10)
Key.removeHotkey(Key.F2, 0)

*****
[error] script [ myHotKey ] stopped with error in line 4
[error] TypeError ( addHotkey(): 3rd arg can't be coerced to org.sikuli.basics.HotkeyListener )
-----

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
masuo
Solved:
Last query:
Last reply:
Revision history for this message
Best masuo (masuo-ohara) said :
#1

Use Key modifiers.
And use Env.addHotkey instead of Key.addHotkey
http://sikulix-2014.readthedocs.io/en/latest/interaction.html?highlight=addHotkey

[example]
def myHandler(event):
    print "inside message"

Env.addHotkey(Key.F2,KeyModifier.SHIFT+KeyModifier.CTRL,myHandler)
wait(10)

Revision history for this message
Karl (k-d) said :
#2
Revision history for this message
RaiMan (raimund-hocke) said :
#4

to clarify:
the deprecation note is for the Java level.

At the Jython level the related feature is in Env.py (not marked as deprecated), to translate the handler to the Java level handler.