RaiMan / SikuliX-2014

SikuliX version 1.1.2 (until February 2018)
http://sikulix.com
805 stars 235 forks source link

Click with key modifiers not working in Python #302

Open imperialguy opened 6 years ago

imperialguy commented 6 years ago

Versions: sikulix 1.1.1 and 1.1.2 (from nightly builds) OS: Windows 7

If I type the following command in SikuliX IDE, it works perfectly fine:

click('sample.png', KEY_SHIFT)

It clicks on the target while holding the SHIFT key simultaneously.

If I do the same thing in python through jnius, the normal click works, but click with key modifiers doesn't work. None of the following three ways of using key modifiers works.

    from jnius import autoclass
    Key = autoclass('org.sikuli.script.Key')
    KeyModifier = autoclass('org.sikuli.script.KeyModifier')
    region.click('sample.png') # works perfectly
    region.click('sample.png', KeyModifier.KEY_SHIFT) # doesn't work
    region.click('sample.png', Key.SHIFT) # doesn't work
    region.click('sample.png', KeyModifier.SHIFT) # doesn't work

They all throw the same error message: JavaException: No methods matching your arguments

Of course, this works perfectly fine without the key modifiers. Please help.

RaiMan commented 6 years ago

as already answered to your direct mail:

sorry, but I have nothing to do with Pyjnius ;-)

I guess the problem is, that something like Key.SHIFT is a static constant and does not have an accessor function.

So autoclass does not implement the access.

region.click() as you use it has this signature: click(String, Integer)

the shift-modifier according to the Java docs is an int 1.

so try: click(image, 1)

To verify the values in the SikuliX IDE simply use print KeyModifier.SHIFT

But you might as well use one of the more sophisticated reflection features of Pyjnius.

Hope it helps.