获取多个按键的组合密码 [英] Get key combination code of multiple keys
问题描述
我想问一下我能否获得多个按键的按键代码组合.例如,我可以从以下示例中获取密钥代码:
I want to ask you can I get key code combination of multiple keys. For example I can get the key code from this example:
public void handle(KeyEvent event) {
if (event.getCode() == KeyCode.TAB) {
}
}
但是我如何获得此示例的关键代码:
But how I can get the key code of this example:
textField.setText("");
// Process only desired key types
if (event.getCode().isLetterKey()
|| event.getCode().isDigitKey()
|| event.getCode().isFunctionKey()) {
String shortcut = event.getCode().getName();
if (event.isAltDown()) {
shortcut = "Alt + " + shortcut;
}
if (event.isControlDown()) {
shortcut = "Ctrl + " + shortcut;
}
if (event.isShiftDown()) {
shortcut = "Shift + " + shortcut;
}
textField.setText(shortcut);
shortcutKeyEvent = event;
} else {
shortcutKeyEvent = null;
}
是否可以获取这些键Ctrl + Tab
或Ctrl + A
的键代码组合?
Is it possible to get the key code combination of these keys Ctrl + Tab
or Ctrl + A
?
推荐答案
不,已处理的keyEvent
仅具有一个主KeyCode
,例如此代码
No, the handled keyEvent
has only one main KeyCode
, for example this code
public void handle(KeyEvent event) {
if (event.getCode() == KeyCode.TAB) {
}
}
将处理TAB
,ALT + TAB
或CTRL + TAB
等.如果仅对CTRL + TAB
感兴趣,则有2个选择:
1)使用isControlDown()
will handle TAB
, ALT + TAB
, or CTRL + TAB
etc. If you only interested in CTRL + TAB
, you have 2 choices:
1) using isControlDown()
public void handle(KeyEvent event) {
if (event.getCode() == KeyCode.TAB && event.isControlDown()) {
}
}
2)使用KeyCodeCombination
2) using KeyCodeCombination
final KeyCombination kb = new KeyCodeCombination(KeyCode.TAB, KeyCombination.CONTROL_DOWN);
...
...
public void handle(KeyEvent event) {
if (kb.match(event)) {
}
}
这篇关于获取多个按键的组合密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!