How to type command+w etc. to use MAC shortcut keys.

Asked by allanlan

hi, i met some problem in using Key Class.
environment:
os: mac osx 10.12 / jdk:1.7 /sikuli 1.1.0 /Java
When i using my app, i'm trying to using COMMAND+W/ COMMAND+Q etc. to switch function. But they does't work.
-----------------
screen.type(Key.F12); //that work well.
but:
screen.type(KeyModifier.CMD+"W"); //it didn't work..

democode:
public static void main(String[] args) throws Exception{
//activity my app such as safari/wechat/system settings etc.
   Time.sleep(10);
   screen.type(Key.F12); //work well.
   screen.type(KeyModifier.CMD+"W"); //didn't work
   System.out.println("CMD:"+Key.getTextFromKeycode(KeyModifier.CMD)); //LOG as CMD:null
 }
so.
if i want to use key: command, command+w, command+Q, how?
i used "KeyModifier.WIN" ,still didn't work.
If you can help, that would be wonderful.thx a lot.

Question information

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

docs should have helped:
http://sikulix-2014.readthedocs.io/en/latest/keys.html#key-constants

type("w", Key.CMD) e.g.

Revision history for this message
allanlan (allan88) said :
#2

hi RaiMan,
    public static void main(String[] args) throws Exception{
            private static Pattern wode = new Pattern("./image/wode.png"); //click item to comfirm that the app actived.
             // TODO Auto-generated method stub
   Time.sleep(2);
   screen.doubleClick(wode);
   Time.sleep(3);
   screen.type("W",Key.CMD);
   screen.type("W",Key.CMD);
 }

console log:
init: Bootstrapping class not in BootstrapTypesSingleton.getInstance()[class=class org.python.core.PyBaseString]
[log] DOUBLE CLICK on L(25,101)@S(0)[0,0 1280x800]
[log] ( ⌘ ) TYPE "W"
[log] ( ⌘ ) TYPE "W

Question is :
log ( ⌘ ) TYPE "W, but it didn't run as command+w(this command would close current window.)

app seemed to have no reply even i try to test system apps.Would u pls debug in your mac book? thx a lot.
I don't know how to solve the problem.

Revision history for this message
allanlan (allan88) said :
#3

Using "screen.type("W",KeyModifier.CMD);" and system reply some sound(keypress sound)
The problem seems to change to how to ensure the app is active?
 how to ensure it can receive and response the ( ⌘ ) TYPE "W" action.
i'm using sikuli ide since 2013. this is the first time: i clicked app item or even typing in textfield to ensure app is selecting/active.
and then it didn't response {screen.type("W",KeyModifier.CMD); }

screen.type(Key.DOWN); //work well.
screen.type("W",KeyModifier.CMD); //didn't respond in current app. why?

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

LOWERCASE w
otherwise it would be CMD-SHIFT-w which surely will not work.

The log should have shown your mistake.

Revision history for this message
allanlan (allan88) said :
#5

thx so much!!!
i thought W just the same with "w".Big mistake.thanks very much!!!