keyDown(Key.WIN) not working - Java problem

Asked by Pablo Frank

keyDown(Key.WIN) does not work and i can not identifie any mistake. (Of course i need the solution for KeyUp(Key.WIN) too ).
When i run keyDown(Key.WIN) I receive this:

[error] Stopped [error] An error occurs at line 1 [error] Error message: Traceback (most recent call last): File "C:\Users\Pablo1\AppData\Local\Temp\sikuli-tmp8949974122222053401.py", line 1, in keyDown(Key.WIN) File "C:\Program Files\Sikuli X\sikuli-script.jar\Lib\sikuli\Region.py", line 215, in keyDown at sun.awt.windows.WRobotPeer.keyPress(Native Method) at java.awt.Robot.keyPress(Unknown Source) at org.sikuli.script.Region.doType(Region.java:943) at org.sikuli.script.Region.type_ch(Region.java:1090) at org.sikuli.script.Region.keyDown(Region.java:641) at org.python.proxies.sikuli.Region$Region$1.super__keyDown(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Invalid key cod

Question information

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

This seems to be a Java problem, but until now, I did not find anything in the net.

Sikuli correctly translates the Key.WIN (u"\ue023") to the Java KeyEvent.VK_META (which is int 157), but the JRE is giving the above exception: invalid key code.

I have tested this using the Java classes directly

import java.awt.Robot as jR
import java.awt.KeyEvent as jKE

k = jKE.VK_META

r = jR() # makes a new robot
r.keyPress(k)
r.keyRelease(k)

resulting in the same error.

In my Mac environment this works perfectly (VK_META on Mac stands for the cmd-key).

Conclusion:
Due to the above Java problem, currently Key.WIN cannot be pressed on Windows. It can only be used as a modifier key
type("r", KEY_WIN)

Revision history for this message
Pablo Frank (frank-pablo) said :
#2

Thanks RaiMan, that solved my question.