示例#1
0
 /// <summary>
 /// Returns true if no key has been pressed that changes the definition
 /// of the "currently pressed" keybind.
 /// </summary>
 private static bool IsKeybindExclusive(Keybinding bind)
 {
     if (bind.UsesModifiers && !bind.UsesKeys)
     {
         return(true);
     }
     if (bind.UsesKeys)
     {
         if (_modifiersdown != bind.Modifiers ||
             bind.Key != RepeatKey)//someone overrode us
         {
             return(false);
         }
     }
     if (bind.UsesMouse)
     {
         //we can conflict with left/right, not others
         int buttonsdown = _mousebuttonsdown.Count;
         if (_mousestate[MouseButton.Left])
         {
             buttonsdown--;
         }
         if (_mousestate[MouseButton.Right])
         {
             buttonsdown--;
         }
         if (buttonsdown > 1)
         {
             return(false);
         }
     }
     return(true);
 }
示例#2
0
 private Hotkey CheckConflicts(Keybinding keybinding, Hotkey hotkey)
 {
     if (!keybinding.IsEmpty)
     {
         var inputconflicts = Settings.KeybindConflicts[hotkey];
         foreach (var keybinds in Settings.Keybinds)
         {
             var hk        = keybinds.Key;
             var conflicts = Settings.KeybindConflicts[hk];
             //if the conflicts is equal to or below inputconflicts
             //then we can compare for conflict
             //if conflicts is above inputconflicts, ignore
             if (inputconflicts.HasFlag(conflicts))
             {
                 foreach (var keybind in keybinds.Value)
                 {
                     if (keybind.IsBindingEqual(keybinding))
                     {
                         return(hk);
                     }
                 }
             }
         }
     }
     return(Hotkey.None);
 }
示例#3
0
        private bool TryNewKeybind(Hotkey hotkey, Keybinding newbind, int kbindex)
        {
            var k        = Settings.Keybinds[hotkey];
            var conflict = CheckConflicts(newbind, hotkey);

            if (conflict == hotkey)
            {
                return(true);
            }
            var prop = GetLabel(hotkey);

            if (conflict != Hotkey.None)
            {
                var mbox = MessageBox.Show(_canvas,
                                           $"Keybinding conflicts with {conflict}, If you proceed you will overwrite it.\nDo you want to continue?",
                                           "Conflict detected", MessageBox.ButtonType.OkCancel);
                mbox.Dismissed += (o, e) =>
                {
                    if (e == DialogResult.OK)
                    {
                        RemoveKeybind(conflict, newbind);
                        ChangeKeybind(prop, hotkey, kbindex, newbind);
                    }
                };
                return(false);
            }
            ChangeKeybind(prop, hotkey, kbindex, newbind);
            return(true);
        }
 public bool IsBindingEqual(Keybinding other)
 {
     if (other == null)
     {
         return(false);
     }
     return(other.Key == Key && other.Modifiers == Modifiers && other.MouseButton == MouseButton);
 }
        public RebindHotkeyWindow(GameCanvas parent, string label) : base(parent, null)

        {
            _binding = new Keybinding();
            _lasthit = _binding;
            Title    = $"Rebind \"{label}\" (ESC to cancel)";
            SetSize(350, 110);
            DisableResizing();
            MakeModal(true);
            Setup();
            KeyboardInputEnabled = true;
            Gwen.Input.InputHandler.KeyboardFocus = this;
        }
 public override void Think()
 {
     base.Think();
     if (IsOnTop)
     {
         var  hk         = InputUtils.ReadHotkey();
         bool changemade = false;
         if (ModifierOnly)
         {
             hk.Key = (OpenTK.Input.Key)(-1);
         }
         if (!hk.IsEmpty)
         {
             if (_lasthit.IsEmpty)
             {
                 _binding   = hk;
                 changemade = true;
             }
             else
             {
                 if (hk.UsesModifiers)
                 {
                     var mods    = InputUtils.SplitModifiers(hk.Modifiers);
                     var oldmods = InputUtils.SplitModifiers(_binding.Modifiers);
                     foreach (var v in mods)
                     {
                         if (!oldmods.Contains(v))
                         {
                             changemade = true;
                         }
                     }
                 }
                 if (hk.UsesKeys && hk.Key != _binding.Key ||
                     hk.UsesMouse && hk.MouseButton != _binding.MouseButton)
                 {
                     changemade = true;
                 }
             }
             if (changemade)
             {
                 _binding      = hk;
                 _kblabel.Text = _binding.ToString();
             }
         }
         if (!hk.IsBindingEqual(_lasthit))
         {
             _lasthit = hk;
         }
     }
 }
示例#7
0
        private void ChangeKeybind(LabelProperty prop, Hotkey hotkey, int kbindex, Keybinding kb)
        {
            var k = Settings.Keybinds[hotkey];

            if (kbindex >= k.Count)
            {
                k.Add(kb);
            }
            else
            {
                Settings.Keybinds[hotkey][kbindex] = kb;
            }
            prop.Value = CreateBindingText(hotkey);
            Settings.Save();
        }
示例#8
0
        private void RemoveKeybind(Hotkey hotkey, Keybinding binding)
        {
            var conflictkeys = Settings.Keybinds[hotkey];

            for (int i = 0; i < conflictkeys.Count; i++)
            {
                if (conflictkeys[i].IsBindingEqual(binding))
                {
                    var conflictprop = GetLabel(hotkey);
                    conflictkeys.RemoveAt(i);
                    conflictprop.Value = CreateBindingText(hotkey);
                    break;
                }
            }
        }
        private static bool CheckPressed(Keybinding bind, ref KeyboardState state)
        {
            if (_window != null && !_window.Focused)
            {
                return(false);
            }
            if (bind.Key != (Key)(-1))
            {
                if (!state.IsKeyDown(bind.Key))
                {
                    return(false);
                }
            }
            if (bind.MouseButton != (MouseButton)(-1))
            {
                if (!_last_mouse_state.IsButtonDown(bind.MouseButton))
                {
                    return(false);
                }
            }
            if (bind.Modifiers != (KeyModifiers)(0))
            {
                var alt =
                    state.IsKeyDown(Key.AltLeft) ||
                    state.IsKeyDown(Key.AltRight);
                var ctrl =
                    state.IsKeyDown(Key.ControlLeft) ||
                    state.IsKeyDown(Key.ControlRight);
                var shift =
                    state.IsKeyDown(Key.ShiftLeft) ||
                    state.IsKeyDown(Key.ShiftRight);

                if ((bind.Modifiers.HasFlag(KeyModifiers.Alt) && !alt) ||
                    (bind.Modifiers.HasFlag(KeyModifiers.Shift) && !shift) ||
                    (bind.Modifiers.HasFlag(KeyModifiers.Control) && !ctrl))
                {
                    return(false);
                }
            }
            return(!bind.IsEmpty);
        }
示例#10
0
        /// <summary>
        /// Returns true if no key has been pressed that changes the definition
        /// of the "currently pressed" keybind.
        /// </summary>
        private static bool IsKeybindExclusive(Keybinding bind)
        {
            int allowedkeys = bind.KeysDown;

            if (allowedkeys > 0 && !IsModifier(bind.Key))
            {
                if (_modifiersdown != bind.Modifiers ||
                    bind.Key != LastPressedKey)//someone overrode us
                {
                    return(false);
                }
            }
            if (bind.UsesMouse)
            {
                if (_mousebuttonsdown.Count > 1)
                {
                    return(false);
                }
            }
            return(true);
        }
示例#11
0
        private static bool CheckPressed(Keybinding bind, ref KeyboardState state, ref MouseState mousestate)
        {
            if (_window != null && !_window.Focused)
            {
                return(false);
            }
            if (bind.Key != (Key)(-1))
            {
                if (!state.IsKeyDown(bind.Key))
                {
                    if (_macOS)
                    {
                        // We remap command to control here.
                        // Ctrl+ keys aren't working properly on osx
                        // I don't know of a better way to handle this platform
                        // issue.
                        switch (bind.Key)
                        {
                        case Key.ControlLeft:
                            if (!state.IsKeyDown(Key.WinLeft))
                            {
                                return(false);
                            }
                            break;

                        case Key.ControlRight:
                            if (!state.IsKeyDown(Key.WinRight))
                            {
                                return(false);
                            }
                            break;

                        default:
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            if (bind.UsesMouse)
            {
                if (!mousestate.IsButtonDown(bind.MouseButton))
                {
                    return(false);
                }
            }
            if (bind.Modifiers != (KeyModifiers)(0))
            {
                var alt =
                    state.IsKeyDown(Key.AltLeft) ||
                    state.IsKeyDown(Key.AltRight);
                var ctrl =
                    state.IsKeyDown(Key.ControlLeft) ||
                    state.IsKeyDown(Key.ControlRight);
                if (_macOS)
                {
                    // Remap the command key to ctrl.
                    ctrl |=
                        state.IsKeyDown(Key.WinLeft) ||
                        state.IsKeyDown(Key.WinRight);
                }
                var shift =
                    state.IsKeyDown(Key.ShiftLeft) ||
                    state.IsKeyDown(Key.ShiftRight);

                if ((bind.Modifiers.HasFlag(KeyModifiers.Alt) && !alt) ||
                    (bind.Modifiers.HasFlag(KeyModifiers.Shift) && !shift) ||
                    (bind.Modifiers.HasFlag(KeyModifiers.Control) && !ctrl))
                {
                    return(false);
                }
            }
            return(!bind.IsEmpty);
        }