Get key combination code

浪尽此生 提交于 2019-11-30 14:19:53

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)) { 
    }
}

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
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!