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

Asked by allanlan on 2017-04-19

hi, i met some problem in using Key Class.
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.
screen.type(KeyModifier.CMD+"W"); //it didn't work..

public static void main(String[] args) throws Exception{
//activity my app such as safari/wechat/system settings etc.
   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
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

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Last query:
Last reply:
RaiMan (raimund-hocke) said : #1

docs should have helped:

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

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

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.

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?

RaiMan (raimund-hocke) said : #4

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

The log should have shown your mistake.

allanlan (allan88) said : #5

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