I’m trying to add keyboard shortcuts to a GWT menu, same as in most windows applications (for example ALT + F, then O -> activates the “File” menu, then “Open” MenuItem ).
I know it may conflict with browser shortcuts, so I’m interested in a way of disabling those too…
From what I can see google has all kinds of shortcuts in their applications so, there must be a way to do this.
Thanks!
Edit
Thanks to Igor’s response I’m able to capture keyboard input before being consumed by other controls.
What I don’t know is how to make the MenuBar show itself (like when mouse hovering). MenuBar doesn’t seem to have a method .open() 🙁
I haven’t actually tried this, but
NativeEventseems to be what you are looking for. You get to it viaEvent.addNativePreviewHandler(Event.NativePreviewHandler):Reference: GWT Google Group thread
To select a menu item programatically, use
MenuBar.selectItem(MenuItem item)– you’ll probably need to keep track of the relevantMenuItems. From the selectedMenuItemyou can get to its sub menu viaMenuItem.getSubMenu()and so on… 🙂 You can play around with the auto-open setting (MenuBar.setAutoOpen(boolean autoOpen)to get it to work like you envisioned.