Java: How to slow down a key combination

Asked by Boipelo Mawasha

I want to minimize the active window without using Screen.click()

The key combination for doing this is: Alt + Space +n

This is how I have it in eclipse:

Screen s = new Screen()
s.type(null, Key.SPACE+ "n", KeyModifier.ALT);

The problem is that it seems to try and hit the keys too quickly and thus, nothing happens.

Any assistance would we welcomed

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Boipelo Mawasha
Solved:
Last query:
Last reply:
Revision history for this message
Boipelo Mawasha (bmawasha) said :
#1

I'm using Sikuli within Eclipse

Revision history for this message
scott f (sfeister) said :
#2

Hi Boipelo,

I have a guess as to your problem. The way you coded it, I think you are first typing "ALT + SPACE" and then typing "ALT + N".

I have never used the "Screen" class, so I don't know if the your syntax with s.type() is right, but perhaps try something like this:

Screen s = new Screen()
keyDown(Key.SPACE) # press and hold the SPACE key
s.type(null, 'n', KeyModifier.CTRL) # type "CTRL + N"
keyUp(Key.SPACE) # release the SPACE key

Let me know if that works!

Sidenote:
If I were trying to type CTRL + ALT + N I would have used:

type('n', KeyModifier.CTRL + KeyModifier.ALT)

Unfortunately, the SPACE key is not allowed as a 'KeyModifier'. Not sure why!

Revision history for this message
scott f (sfeister) said :
#3

I just realized that the keyDown/keyUp syntax is probably slightly different in Eclipse. Also, comments are probably not with hashes. You'll need to adapt the syntax what I suggested based on your Java skills! That part is out of my league.

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

@ scott
principally ok and should be the solution with some added waits.

Screen s = new Screen();
s.keyDown(Key.SPACE); // press and hold the SPACE key
s.wait(0.3);
s.type(null, 'n', KeyModifier.ALT); // type "CTRL + N"
s.keyUp(Key.SPACE); // release the SPACE key

Revision history for this message
Boipelo Mawasha (bmawasha) said :
#5

Thanks a lot guys.

It worked, but I had to tweak it. It seems that the ALT key has to be pressed first for this to work. Here's the code I used:

s.keyDown(Key.ALT);
s.wait(0.3);
s.type(null,Key.SPACE + "n", 0);
s.keyUp(Key.ALT);

Revision history for this message
Boipelo Mawasha (bmawasha) said :
#6

Thanks again