java - JavaFX 中的 KeyCode 组合 Control + LEFT 或 Ctrl + RIGHT 键

标签 java javafx keycode

我正在尝试构建一个视频播放器。因为我想使用 CtrlLEFTRIGHT 键来查找媒体。

我尝试了两种方式:

KeyCombination.keyCombination("Ctrl+RIGHT").match(e);

KeyCodeCombination(KeyCode.LEFT, KeyCombination.CONTROL_DOWN).match(e);

其他组合键有效,但这些组合键无效。

有什么办法可以实现吗?

最佳答案

您可以尝试使用SHORTCUT_DOWN而不是 CONTROL_DOWN,因为第一个是独立于平台的。

Returns whether or not the host platform common shortcut modifier is down on this event. This common shortcut modifier is a modifier key which is used commonly in shortcuts on the host platform. It is for example control on Windows and meta (command key) on Mac.

然后你有几个机会,例如:

node.setOnKeyPressed(e -> {
    if (new KeyCodeCombination(KeyCode.LEFT, KeyCombination.SHORTCUT_DOWN).match(e)) {
        // ...
    }
});

node.setOnKeyPressed(e -> {
    if (e.getCode() == KeyCode.LEFT && e.isShortcutDown()) {
        // ...
    }
});

关于java - JavaFX 中的 KeyCode 组合 Control + LEFT 或 Ctrl + RIGHT 键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39605707/

相关文章:

java - ms Graph api(beta) 访问被拒绝

java - 找不到符号 event.getKeyCode()

安卓静音键

java - 所有类都应该有 .equals 和 .hashcode 方法吗?

java - 为什么 Java Swing html 字体渲染看起来这么糟糕?

java - 如何使用外部 css 文件来设计 javafx 应用程序的样式

css - 如何摆脱 JavaFX 2 中 Pane 分隔符内的拆分 Pane 分隔符中的三个小点?

javascript - 如何在 JavaFX WebView 组件中加载本地镜像

delphi - Ctrl+-(Ctrl+连字符-减号)作为快捷键?

java - 火存储 : Query all collections orderBy and startsWith last 1 result