public override bool ProcessKey(KeyEvent kb) { bool disabled; switch (kb.Key) { case Key.CursorUp: if (barItems.IsTopLevel || current == -1) { break; } do { disabled = false; current--; if (host.UseKeysUpDownAsKeysLeftRight) { if (current == -1 && barItems.Children [current + 1].IsFromSubMenu && host.selectedSub > -1) { current++; host.PreviousMenu(true); break; } } if (current < 0) { current = barItems.Children.Length - 1; } var item = barItems.Children [current]; if (item == null || !item.IsEnabled()) { disabled = true; } } while (barItems.Children [current] == null || disabled); SetNeedsDisplay(); break; case Key.CursorDown: if (barItems.IsTopLevel) { break; } do { current++; disabled = false; if (current == barItems.Children.Length) { current = 0; } var item = barItems.Children [current]; if (item == null || !item.IsEnabled()) { disabled = true; } if (host.UseKeysUpDownAsKeysLeftRight && barItems.Children [current]?.SubMenu != null && !disabled && !host.isMenuClosed) { CheckSubMenu(); break; } if (host.isMenuClosed) { host.OpenMenu(host.selected); } } while (barItems.Children [current] == null || disabled); SetNeedsDisplay(); break; case Key.CursorLeft: host.PreviousMenu(true); break; case Key.CursorRight: host.NextMenu(barItems.IsTopLevel || barItems.Children [current].IsFromSubMenu ? true : false); break; case Key.Esc: Application.UngrabMouse(); host.CloseAllMenus(); break; case Key.Enter: if (barItems.IsTopLevel) { Run(barItems.Action); } else { CheckSubMenu(); Run(barItems.Children [current].Action); } break; default: // TODO: rune-ify if (barItems.Children != null && Char.IsLetterOrDigit((char)kb.KeyValue)) { var x = Char.ToUpper((char)kb.KeyValue); foreach (var item in barItems.Children) { if (item == null) { continue; } if (item.IsEnabled() && item.HotKey == x) { host.CloseMenu(); Run(item.Action); return(true); } } } break; } return(true); }