我正在尝试构建一个视频播放器。因为我想使用 Ctrl 和 LEFT 和 RIGHT 键来查找媒体。
我尝试了两种方式:
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/