keyDown(Key.SHIFT) not working on Win with Num-Lock on -- switch it off ;-)

Asked by Jason

**** it is a Java bug, but there is a workaround

Unfortunately, this is a bug of Java robot and we may not be able to fix it. (http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=cfc56061b7ccaa1709a312de159d4?bug_id=4908075)

A workaround is to turn off the num lock.
There will be a new API Env.isLockOn() in RC2 to get the state of locking keys. So one can use Env.isLockOn(Key.NUM_LOCK) to know the state of the num lock, and then use type(Key.NUM_LOCK) to turn it off if needed.

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

I have this same script for Mac and Windows. On Mac, it works as expected, but it looks like the shift key isn't pressed on Windows.

Have notepad open with text "asdf" and run the code below:
keyDown(Key.SHIFT)
type(Key.LEFT)
type(Key.LEFT)
type(Key.LEFT)
keyUp(Key.SHIFT)

It should highlight "sdf", but on Windows, it only moves the cursor between "a" and "s" as if it only moved left 3 times without shift key down.

Is this a bug? Any work around?

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
RaiMan (raimund-hocke) said :
#1

The selection in the Notepad window is lost, when Notepad loses focus.

If you put a wait(3) after your sequence, you can see the select happen ;-)

This worked for me on Win7 with X 1.0rc1:

n = App("notepad")
n.focus(); wait(1)
type("asdf")
keyDown(Key.SHIFT)
type(Key.LEFT)
type(Key.LEFT)
type(Key.LEFT)
keyUp(Key.SHIFT)
type("c", KEY_CTRL)
print Env.getClipboard()

Revision history for this message
Jason (jasonyoo) said :
#2

That doesn't work on my XP machine. Same thing happens, it only moves the cursor between "a" and "s".

I tried adding 3 seconds at the end, but no luck. :(

Revision history for this message
Jason (jasonyoo) said :
#3

I just noticed that this works if the Num Lock is not on.
How do you make sure that the Num Lock is off in Sikuli script? And why is this effecting the Shift key?

Revision history for this message
Best RaiMan (raimund-hocke) said :
#4

Oh yes sorry, I'm a Mac usually. Did not remember that.

Num Lock is a problem (shift not working with num-lock on, there is a bug report ;-), that will be solved with rc2. Now you have to look at it on your own.

Revision history for this message
RaiMan (raimund-hocke) said :
#5

@ Jason
pls add youself as affected in the bug

Revision history for this message
Jason (jasonyoo) said :
#6

Thanks RaiMan, that solved my question.

Revision history for this message
Tsung-Hsiang Chang (vgod) said :
#7

Unfortunately, this is a bug of Java robot and we may not be able to fix it. (http://bugs.sun.com/bugdatabase/view_bug.do;jsessionid=cfc56061b7ccaa1709a312de159d4?bug_id=4908075)

A workaround is to turn off the num lock.
There will be a new API Env.isLockOn() in RC2 to get the state of locking keys. So one can use Env.isLockOn(Key.NUM_LOCK) to know the state of the num lock, and then use type(Key.NUM_LOCK) to turn it off if needed.

Revision history for this message
Elyashevskyy Ostap (osai) said :
#8

Have the same issue, WinXP via RDP (sikuli is installed on remote machine), but solution to turn off NUM LOCK does not help (
If you have any updates let me know please.