private bool VerifyShortcut(KeyEventArgs args) { OPMShortcut cmd = ShortcutMapper.MapCommand(args.KeyData); if (cmd == OPMShortcut.CmdOutOfRange) { // Key combination currently not assigned so it's OK to use it. return(true); } if (cmd == _cmd) { // Same command => ok to reassign. return(true); } string cmdOld = cmd.ToString().Replace("Cmd", string.Empty); string cmdNew = _cmd.ToString().Replace("Cmd", string.Empty); KeysConverter kc = new KeysConverter(); string key = kc.ConvertToInvariantString(args.KeyData); if ((args.KeyData == Keys.Space && ShortcutMapper.IsPlayer) || !ShortcutMapper.IsConfigurableShortcut(cmd)) { // Key combination currently assigned // to a non-configurable command (e.g. F1 = help) MessageDisplay.Show(Translator.Translate("TXT_DUP_SHORTCUT_FIXED", key, cmdOld), Translator.Translate("TXT_DUPPLICATE_SHORTCUT"), MessageBoxIcon.Warning); return(false); } if (MessageDisplay.Query(Translator.Translate("TXT_DUP_SHORTCUT_CONFIRM", key, cmdOld, cmdNew), Translator.Translate("TXT_DUPPLICATE_SHORTCUT"), MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.Yes) { // Key combination already assigned and the user did not want to change it use it. return(false); } // Unassign old shortcut if (ShortcutMapper.KeyCommands[(int)cmd].KeyData == args.KeyData) { // Was used for primary shortcut ShortcutMapper.KeyCommands[(int)cmd] = new KeyEventArgs(Keys.None); } else if (ShortcutMapper.AltKeyCommands[(int)cmd].KeyData == args.KeyData) { // Was used for alternate shortcut ShortcutMapper.AltKeyCommands[(int)cmd] = new KeyEventArgs(Keys.None); } return(true); }
protected bool ProcessKeyDown(Control ctlSender, Keys key, Keys modifiers) { if (modifiers == Keys.None && AllowCloseOnKeyDown(key)) { DialogResult = MapDialogResult(key); Close(); return(false); } else { OPMShortcut cmd = ShortcutMapper.MapCommand(key); if (IsShortcutAllowed(cmd)) { ShortcutMapper.DispatchCommand(cmd); return(false); } } return(true); }