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;
}
Is it possible to get the key code combination of these keys Ctrl + Tab
or Ctrl + A
?
No, the handled
keyEvent
has only one mainKeyCode
, for example this codewill handle
TAB
,ALT + TAB
, orCTRL + TAB
etc. If you only interested inCTRL + TAB
, you have 2 choices:1) using isControlDown()
2) using KeyCodeCombination
I Don't see directly there is any way except Menus but still We can handle multi key event e.g. Ctrl + S by below work around.
at controller class level keep
and in Event filter add logic as