JavaFx:快捷键
Posted xhBruce
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaFx:快捷键相关的知识,希望对你有一定的参考价值。
JavaFx:快捷键
KeyCombination.html
KeyCode.html
设置方式参考:JavaFX 设置快捷键、JavaFx:11、设置快捷键、JavaFX学习:快捷键
快捷键CTRL + C
KeyCombination ctrl_c = new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_DOWN);
window.getScene().getAccelerators().put(ctrl_c, () -> {
System.out.println("快捷键CTRL + C");
System.out.println(Thread.currentThread().getName());
});
或设置KeyCombination ctrl_c = new KeyCodeCombination(KeyCode.C, KeyCombination.SHORTCUT_DOWN);
- 监听eventFilter
window.addEventFilter(KeyEvent.KEY_PRESSED, e -> {
//System.out.println("KeyEvent = " + e);
if (ctrl_c.match(e)) {
System.out.println("快捷键CTRL + C");
System.out.println(Thread.currentThread().getName());
}
});
快捷键CTRL + V
KeyCombination ctrl_v = new KeyCodeCombination(KeyCode.V, KeyCombination.CONTROL_DOWN);
window.getScene().getAccelerators().put(ctrl_v, () -> {
System.out.println("快捷键CTRL + V");
System.out.println(Thread.currentThread().getName());
});
快捷键SHIFT + C
KeyCombination shift_c = new KeyCodeCombination(KeyCode.C, KeyCombination.SHIFT_DOWN);
window.getScene().getAccelerators().put(shift_c, () -> {
System.out.println("快捷键SHIFT + C");
System.out.println(Thread.currentThread().getName());
});
快捷键WIN + C(没有实现)
win10默认启动Cortana;长按WIN
后,通过eventFilter监听,点击单个字符(如C
)无响应
KeyEvent.java中 isShortcutDown()
、isControlDown()
、isAltDown()
、isShiftDown()
、isMetaDown()
KeyEvent = KeyEvent [source = javafx.stage.Stage@228108b4, target = ScrollPane@16dbfdbe[styleClass=scroll-pane], eventType = KEY_PRESSED, consumed = false, character = , text = , code = WINDOWS, metaDown]
KeyEvent = KeyEvent [source = javafx.stage.Stage@228108b4, target = ScrollPane@16dbfdbe[styleClass=scroll-pane], eventType = KEY_PRESSED, consumed = false, character = , text = , code = UNDEFINED, controlDown, shortcutDown]
KeyEvent = KeyEvent [source = javafx.stage.Stage@228108b4, target = ScrollPane@16dbfdbe[styleClass=scroll-pane], eventType = KEY_PRESSED, consumed = false, character = , text = , code = ALT, controlDown, altDown, shortcutDown]
KeyEvent = KeyEvent [source = javafx.stage.Stage@228108b4, target = ScrollPane@16dbfdbe[styleClass=scroll-pane], eventType = KEY_PRESSED, consumed = false, character = , text = , code = WINDOWS, controlDown, altDown, metaDown, shortcutDown]
KeyEvent = KeyEvent [source = javafx.stage.Stage@228108b4, target = ScrollPane@16dbfdbe[styleClass=scroll-pane], eventType = KEY_PRESSED, consumed = false, character = , text = , code = SHIFT, shiftDown, controlDown, altDown, metaDown, shortcutDown]
快捷键ALT +V
KeyCombination alt_v = new KeyCodeCombination(KeyCode.V, KeyCombination.ALT_DOWN);
window.getScene().getAccelerators().put(alt_v, () -> {
System.out.println("快捷键ALT + V");
System.out.println(Thread.currentThread().getName());
});
快捷键CTL + ALT + C
KeyCombination ctrl_alt_c = new KeyCodeCombination(KeyCode.C, KeyCombination.ALT_DOWN, KeyCombination.CONTROL_DOWN);
window.getScene().getAccelerators().put(ctrl_alt_c, () -> {
System.out.println("快捷键CTL + ALT + C");
System.out.println(Thread.currentThread().getName());
});
以上是关于JavaFx:快捷键的主要内容,如果未能解决你的问题,请参考以下文章