Get the key combination code

I want to ask if I can get a key code combination of several keys. For example, I can get key code in this example:

public void handle(KeyEvent event) { if (event.getCode() == KeyCode.TAB) { } 

But how can I 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 ?

+6
source share
1 answer

No, the processed keyEvent has only one main KeyCode , for example, this code

 public void handle(KeyEvent event) { if (event.getCode() == KeyCode.TAB) { } } 

will handle TAB , ALT + TAB or CTRL + TAB , etc. If you are only interested in CTRL + TAB , you have 2 options:
1) using isControlDown ()

 public void handle(KeyEvent event) { if (event.getCode() == KeyCode.TAB && event.isControlDown()) { } } 

2) using KeyCodeCombination

 final KeyCombination kb = new KeyCodeCombination(KeyCode.TAB, KeyCombination.CONTROL_DOWN); ... ... public void handle(KeyEvent event) { if (kb.match(event)) { } } 
+11
source

Source: https://habr.com/ru/post/954582/


All Articles