So I want to for example press CTRL + Alt + D and something happens. And that without a window from javafx (which I use). So then I can press this key combination everytime (if my application is on). Is that possible? If yes how would I do that?
Asked
Active
Viewed 42 times
0
-
1Maybe this can help you: https://stackoverflow.com/questions/79658/react-on-global-hotkey-in-a-java-program-on-windows-linux-mac *Spoiler* you need JNI. – jmizv Sep 11 '20 at 09:18
-
thanks I will try that – Jan Tennert Sep 11 '20 at 09:23
-
3Does this answer your question? [React on global hotkey in a Java program on Windows/Linux/Mac?](https://stackoverflow.com/questions/79658/react-on-global-hotkey-in-a-java-program-on-windows-linux-mac) – Scratte Sep 11 '20 at 16:50
-
yes that worked – Jan Tennert Sep 11 '20 at 18:33
-
but if I want to change anything from javafx I need Platform.runLater and that is only called one time (if I press once its working but the second time nothing happens) – Jan Tennert Sep 11 '20 at 18:44
1 Answers
0
Add to your primaryStage scene something like this:
primaryStage.getScene().setOnKeyPressed(keyEvent -> {
KeyCombination combination = new KeyCodeCombination(KeyCode.D,KeyCombination.CONTROL_DOWN,KeyCombination.ALT_DOWN);
if (combination.match(keyEvent)) {
System.out.println("Ctrl+Alt+D was pressed");
}
});