我想将JavaFX按钮的操作绑定到键盘键上。

我需要以下功能:
发布于 2017-03-26 16:06:26
做这个,你可以用EventFilters
如果您希望只在按下一个键时才触发它:
addEventFilter(KeyEvent.KEY_PRESSED, event ->
{
if(event.getCode().equals(KeyCode.DIGIT1))
{
System.out.println("1 Pressed");
//Then either call the method directly
selectOneFile();
//Or fire the button
selectOneFileBtn.fire();
}
});但是,正如@ItachiUchiha (和我)所建议的那样,您应该使用键的组合:
addEventFilter(KeyEvent.KEY_PRESSED, event ->
{
if(event.isAltDown() && event.getCode().equals(KeyCode.DIGIT1))
{
System.out.println("Alt + 1 Pressed");
//Then again, either call the method directly
selectOneFile();
//Or fire the button
selectOneFileBtn.fire();
}
});https://stackoverflow.com/questions/43026983
复制相似问题