Get key combination code of multiple keys

后端 未结 2 1735
遥遥无期
遥遥无期 2021-01-02 11:32

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:

<         


        
相关标签:
2条回答
  • 2021-01-02 12:19

    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

    public static boolean halfCtrlSPressed=false;
    

    and in Event filter add logic as

    if(ke.getCode().getName() == "Ctrl") {
                halfCtrlSPressed=true;
            }else if(ke.getCode().getName() == "S"  && halfCtrlSPressed) {
                halfCtrlSPressed=false;
                //doDomething
    }
    
    0 讨论(0)
  • 2021-01-02 12:25

    No, the handled 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 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) using KeyCodeCombination

    final KeyCombination kb = new KeyCodeCombination(KeyCode.TAB, KeyCombination.CONTROL_DOWN);
    ...
    ...
    public void handle(KeyEvent event) {
        if (kb.match(event)) { 
        }
    }
    
    0 讨论(0)
提交回复
热议问题