开发者

Control a Windows apps using Java

I would like to know if there is any way I can control a Windows application using Java code. 开发者_如何学JAVAI have already googled it, and found that it can be done using JNI or a library called NewJawin.

I want to control Windows Media Player using Java code, e.g. play, pause, and change songs, but could find no relevant example to get me started so far. Do you guys have any suggestion?


As no one has answered this question, I thought I would.

public void firePlay() {
    //CTRL + P
    //import java.awt.Robot
    //import java.awt.KeyEvent
    try {
        Robot robot = new Robot();
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_P);
        robot.keyRelease(KeyEvent.VK_P);
        robot.keyRelease(KeyEvent.VK_CONTROL);
    } catch (AWTException ex) {
        Logger.getLogger(atest.class.getName()).log(Level.SEVERE, null, ex);
    }
}

This would play/pause the video. You can see other shortcuts here(http://windows.microsoft.com/en-AU/windows-vista/Windows-Media-Player-keyboard-shortcuts)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜