void SetAccelerators(ISubMenuWidget item) { if (item != null && item.MenuItems != null) { foreach (var child in item.MenuItems) { var actionItem = child as MenuActionItem; if (actionItem != null && actionItem.Shortcut != Key.None) { var widget = actionItem.ControlObject as Gtk.Widget; var key = new Gtk.AccelKey(KeyMap.ConvertToKey(actionItem.Shortcut), KeyMap.ConvertToModifier(actionItem.Shortcut), Gtk.AccelFlags.Visible | Gtk.AccelFlags.Locked); widget.AddAccelerator("activate", accelGroup, key); } SetAccelerators(child as ISubMenuWidget); } } }
void GtkControlObject_KeyPressEvent(object o, Gtk.KeyPressEventArgs args) { Key key = Key.None; key |= KeyMap.Convert(args.Event.Key); Gdk.ModifierType state = args.Event.State; key |= KeyMap.Convert(state); //args.Event. = false; //.RetVal = false; //Console.WriteLine("{0} | {1} | {2} | {3}", args.Event.Key.ToString(), args.Event.State.ToString(), this.Widget.ToString(), key.ToString()); if (key != Key.None) { KeyPressEventArgs kpea; Key modifiers = (key & Key.ModifierMask); if (args.Event.KeyValue <= 128 && ((modifiers & ~Key.Shift) == 0)) { kpea = new KeyPressEventArgs(key, (char)args.Event.KeyValue); } else { kpea = new KeyPressEventArgs(key); } Widget.OnKeyDown(kpea); if (kpea.Handled) { args.RetVal = true; } } else if (args.Event.KeyValue <= 128) { KeyPressEventArgs kpea; kpea = new KeyPressEventArgs(key, (char)args.Event.KeyValue); Widget.OnKeyDown(kpea); if (kpea.Handled) { args.RetVal = true; } } }