0

我有一个 JavaFX 应用程序,当应用程序在后台或最小化时,它需要监听 ctrl+space+T 以将应用程序窗口置于最前面。我可以知道是否有人有解决方案?

public class MainApp extends Application {

@Override
public void start(Stage primaryStage) {
    primaryStage = setStagePositionToBottomRight(primaryStage);
    loadAndStartMainScreen(primaryStage);
}

private void loadAndStartMainScreen(Stage primaryStage) {
    MainViewController scenes = new MainViewController();
    AnchorPane mainScene = scenes.getMainView();
    Scene scene = new Scene(mainScene);
    primaryStage.setScene(scene);
    primaryStage.show();

}



private Stage setStagePositionToBottomRight(Stage primaryStage) {
    final int coordinateX = 335;
    final int coordinateY = 510;

    Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();
    // primaryStage.initStyle(StageStyle.UNDECORATED);
    primaryStage.setX(primaryScreenBounds.getMaxX() - coordinateX);
    primaryStage.setY(primaryScreenBounds.getMaxY() - coordinateY);

    return primaryStage;

}

public static void main(String[] args) {
    launch(args);
}
}
4

2 回答 2

1

I think your requirement can't be implemented in pure java, you'll need some native code to accomplish this.

If you don't want do write everything on your own and your application is running on windows you can take a look at JIntellitype that offers global hotkey functionality.

于 2013-11-04T15:00:20.713 回答
0

对于任何有类似问题的人:

通过侦听所有用户输入,您可以简单地侦听所需的组合键,但这需要额外的库。认为这不是一个好的解决方案,这是一个有效的解决方案。

链接 #1:关于 Java 中的全局事件监听器和链接 #2 的来源

在 Java 中没有焦点的情况下监听输入

链接 #2:具有 Windows、Linux、MacOS X 所需功能的库

https://github.com/kwhat/jnativehook

于 2017-06-19T20:03:39.813 回答