In my stage I have inserted a menubar at the top like usual for programs. I want to give the ALT key (together with arrow keys) some logic in another context within the stage. But everytime I press ALT and arrows I unintentionally navigate through the menus of the menubar, too.
I want to avoid that or better completely disable this mnemonic behavior. Setting the mnemonicParsing properties of all menus to false failed. I also tried this approach without success:
menubar.addEventFilter(KeyEvent.ANY, e -> e.consume());
When ALT is pressed first menu gets focus and when menus have focus, arrow keys cause navigation among them whether ALT is pressed or not. So in order to prevent this behavior you need to prevent first menu getting focus when ALT is pressed.
Looking at the
MenuBarSkinclass' constructor source code, gives us the solution:Solution:
As you had already guessed, solution is to consume the event when ALT is down but you need to add the EventHandler to the
scenenotmenubar: