Key shortcuts for this menu item.
If Key <> K_None and user will press this Key then this object's DoCommand will be called (and TCastleWindowBase.EventMenuCommnd, and TCastleWindowBase.OnMenuCommand, if DoCommand returns false). Similiar, is CharKey <> #0 and user will press a key with CharKey then it will be treated as this menu item click.
Such key press redirection is handled internally in CastleWindow (possibly it's even internally handled in some library on top of which CastleWindow is implemented, e.g. WinAPI and GTK menus can be explicitly connected with some key press (i.e. without doing any special redirection keypress -> DoCommand in CastleWindow). So you will not get EventPress (OnPress) messages for such keypresses (that translate to menu click). Although TCastleWindowBase.Pressed.Keys will be appropriately updated, of course.
Note: Caption of this object should not contain description of Key and CharKey , such description will be automatically shown to user (maybe by adding something like ' [Ctrl+O]' to displayed Caption, maybe in some better (more visually-pleasing) way).
Note: you don't have to give really corresponding Key and CharKey values, as such correspondency may be dependent on state of modifier keys and OS configuration.
In fact, usually you SHOULD give Key = K_None or c = #0. E.g. you should NOT set Key = K_C and CharKey = 'c'. Instead you should set Key = K_C and CharKey = #0 or Key = K_None and CharKey = 'c'. This way you avoid some uncertainty: Key = K_C is something other than CharKey = 'c' (e.g. Shift+C generates K_C, but does not translate as CharKey = 'c' (it is translated as CharKey = 'C' ('C' uppercase !)).
Notes about CharKey values #8 (CharBackSpace = CtrlH), #9 (CharTab = CtrlI), #13 (CharEnter = CtrlM): these are problematic, since they may mean backspace/tab/enter or combinations with Ctrl key. Our algorithm to deal with this:
If your CharKey is one of the CharBackSpace/Tab/Enter constants, and Key is K_None, then you mean the combination with Ctrl key. That's how it's displayed, and moreover: keyboard presses with K_BackSpace/K_Tab/K_Enter do not trigger this menu item.
This way menu items with Ctrl+H or Ctrl+M or Ctrl+I do not block you from assigning keyboard K_BackSpace/K_Tab/K_Enter to some other useful action.
If you really want to assign keyboard backspace/tab/enter presses to menu item, use TKey constants K_BackSpace, K_Tab, K_Enter.
Design notes: I am no longer using TMenuItemKey class. Instead I put this functionality into base TMenuItem class. Before, I had in this class TMenuItemChecked functionality, but it's better to put here TMenuItemKey functionality. That's because in this class we have a natural way to specify TMenuItem that does not translate to any key (Key = K_None and CharKey = #0). While with TMenuItemChecked it would require additional property ShowChecked. And I HAVE to integrate into TMenuItem class some functionality – otherwise, if I would separated both TMenuItemKey and TMenuItemChecked classes, then I would be forced to create additional TMenuItemKeyChecked class.
TODO: change these to writeable
|