使用 Java 控制 Windows 应用程序 [英] Control a Windows apps using Java
问题描述
我想知道是否有任何方法可以使用 Java 代码控制 Windows 应用程序.我已经在谷歌上搜索过了,发现可以使用 JNI 或名为 NewJawin 的库来完成.
I would like to know if there is any way I can control a Windows application using Java code. I have already googled it, and found that it can be done using JNI or a library called NewJawin.
我想使用 Java 代码控制 Windows Media Player,例如播放、暂停和更改歌曲,但到目前为止找不到相关示例让我开始.大家有什么建议吗?
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);
}
}
这将播放/暂停视频.您可以在此处(http://windows.microsoft.com/en-AU/windows-vista/Windows-Media-Player-keyboard-shortcuts)
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)
这篇关于使用 Java 控制 Windows 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!