2013-02-05 51 views

回答

0

使您的根節點成爲焦點,然後在setOnKeyPressed方法中編寫您的邏輯。

示例代碼:

root.setFocusTraversable(true); 
root.setOnKeyPressed(new EventHandler<KeyEvent>() { 

    @Override 
    public void handle(KeyEvent kEvent) { 
     if (kEvent.getCode() == KeyCode.SPACE) { 
      System.out.println("Space Bar pressed"); 
     } 
    } 
});