Keyboard operation of menus

I’ve been looking into the interaction between the keyboard and menus in my apps. And I’ve noticed a few things that diverge from the “standard” way of doing things.

  1. When a BMenuItem with a shortcut is triggered by the user pressing the shortcut keys, the menu item sends it’s command, but also the view with the focus receives the same key press as well. In my case this was causing the command to be executed twice in my edit control. Things like cut and copy have handlers in the OnKey as in some cases it’s used in an app without Edit->Cut/Copy menus and still has to function as you’d expect. But in an app WITH a menu that has Edit->Cut/Copy the commands were running twice because unlike all the other OS’s Haiku doesn’t “eat” the keypress at the menu level. Or maybe I’m doing it wrong. Haha. Is that expected behavior?

  2. The Menu key. In Win/Linux/Mac the menu key on the keyboard will send a key event to the window with the focus. The application will then be able to show a context menu. In Haiku however the system doesn’t send the key event to the application and just shows the deskbar menu. And the “Windows” key (at least on my keyboard) does nothing (maps to ‘Option’ in the keymap). That’s the key that should bring up the system menu. This is in the context of my vmware install and I’m using the US-international keymap. Is there some way to give the app that key?

We are different from other OS here.

The “menu” key being missing on most laptops, it’s hard to use it for anything really useful. So we wired it to open DeskBar. This could be changed.

The “window” key (Option) is usable in apps if you want. However, keep two things in mind:

  • It is used by the OS, in particular for Stack and Tile (when you are dragging a window around, you can use this key to stack or tile it with other windows)
  • The same “Option” key is also used for the AltGr key on non-US keyboards. Having that open a menu or, really, do anything else, would be really annoying, since that’s the key used to type characters like €, @, |, \ (depending on the exact keyboard layout used).

Unfortunately, it is not so easy to fix this, it may need adding an extra “modifier” key, which in turn requires changing the keymap format, which breaks the API of get_key_map. Unless we make one of the modifiers not actually allow to access extra keymap ‘planes’, this would be quirky to implement, but could work.

Seems like a bug. Now we have to find if it’s a bug in Haiku or in your code :slight_smile:

2 Likes