Пример #1
0
 public static Keybinding EditKeybinding(string ID, Keybinding bind)
 {
     if (_keybindings.ContainsKey(ID))
     {
         bind.ID          = ID;
         _keybindings[ID] = ID;
     }
     else
     {
         throw new Exception("Keybinding ID Doesn't Exist. Make Sure a keybinding with that ID has been registered");
     }
     return(bind);
 }
Пример #2
0
        public static Keybinding RegisterKeyBinding(string ID, string Category, Keys[] keys, string[] mouseinput, bool Override)
        {
            if (_keybindings.ContainsKey(ID) && !Override)
            {
                return(new Keybinding());
            }
            else if (_keybindings.ContainsKey(ID) && Override)
            {
                _keybindings.Remove(ID);
            }
            string[] bindingkeys = new string[keys.Length + mouseinput.Length];
            Keys     key;

            for (int i = 0; i < keys.Length; i++)
            {
                key = keys[i];
                if (lowercase.ContainsKey(key))
                {
                    bindingkeys[i] = lowercase[key].ToString();
                }
                if (key == Keys.LeftShift || key == Keys.RightShift)
                {
                    bindingkeys[i] = "shift";
                }
                if (key == Keys.RightControl || key == Keys.LeftControl)
                {
                    bindingkeys[i] = "ctrl";
                }
                if (key == Keys.LeftAlt || key == Keys.RightAlt)
                {
                    bindingkeys[i] = "alt";
                }
                if (key == Keys.Tab)
                {
                    bindingkeys[i] = "tab";
                }
                if (key == Keys.CapsLock)
                {
                    bindingkeys[i] = "caps";
                }
                if (key == Keys.Delete)
                {
                    bindingkeys[i] = "del";
                }
                if (key == Keys.Enter)
                {
                    bindingkeys[i] = "enter";
                }
                if (key == Keys.Back)
                {
                    bindingkeys[i] = "back";
                }
                if (key == Keys.Up)
                {
                    bindingkeys[i] = "up";
                }
                if (key == Keys.Down)
                {
                    bindingkeys[i] = "down";
                }
                if (key == Keys.Left)
                {
                    bindingkeys[i] = "left";
                }
                if (key == Keys.Right)
                {
                    bindingkeys[i] = "right";
                }
                if (key == Keys.PageUp)
                {
                    bindingkeys[i] = "pgUp";
                }
                if (key == Keys.PageDown)
                {
                    bindingkeys[i] = "pgDn";
                }
                if (key == Keys.Insert)
                {
                    bindingkeys[i] = "ins";
                }
                if (key == Keys.Home)
                {
                    bindingkeys[i] = "home";
                }
                if (key == Keys.End)
                {
                    bindingkeys[i] = "end";
                }
                if (key == Keys.Escape)
                {
                    bindingkeys[i] = "esc";
                }
                if (key == Keys.PrintScreen)
                {
                    bindingkeys[i] = "prntScr";
                }
                if (key == Keys.F1)
                {
                    bindingkeys[i] = "f1";
                }
                if (key == Keys.F2)
                {
                    bindingkeys[i] = "f2";
                }
                if (key == Keys.F3)
                {
                    bindingkeys[i] = "f3";
                }
                if (key == Keys.F4)
                {
                    bindingkeys[i] = "f4";
                }
                if (key == Keys.F5)
                {
                    bindingkeys[i] = "f5";
                }
                if (key == Keys.F6)
                {
                    bindingkeys[i] = "f6";
                }
                if (key == Keys.F7)
                {
                    bindingkeys[i] = "f7";
                }
                if (key == Keys.F8)
                {
                    bindingkeys[i] = "f8";
                }
                if (key == Keys.F9)
                {
                    bindingkeys[i] = "f9";
                }
                if (key == Keys.F10)
                {
                    bindingkeys[i] = "f10";
                }
                if (key == Keys.F11)
                {
                    bindingkeys[i] = "f11";
                }
                if (key == Keys.F12)
                {
                    bindingkeys[i] = "f12";
                }
            }
            mouseinput.CopyTo(bindingkeys, keys.Length);
            Keybinding binding = new Keybinding();

            binding.ID          = ID;
            binding.Keys        = bindingkeys;
            binding.Pulse       = false;
            binding.Toggle      = false;
            binding.Held        = false;
            binding.Repeat      = false;
            binding.TogglePulse = false;
            binding.Category    = Category;

            Keybinding bind;

            bool found = true;

            foreach (Keybinding kebind in _keybindings.Values)
            {
                if (kebind.Category == Category)
                {
                    found = true;
                    if (kebind.Keys.Length == bindingkeys.Length)
                    {
                        foreach (string k in kebind.Keys)
                        {
                            if (!bindingkeys.Contains(k))
                            {
                                found = false;
                            }
                        }
                    }
                    if (found)
                    {
                        bind                    = (Keybinding)_keybindings[kebind.ID];
                        bind.Repeat             = true;
                        _keybindings[kebind.ID] = bind;
                        binding.Repeat          = true;
                    }
                }
            }

            _keybindings.Add(ID, binding);

            return(binding);
        }
Пример #3
0
 public static bool getToggle(string ID)
 {
     _tempbinding = (Keybinding)_keybindings[ID];
     return(_tempbinding.Toggle);
 }
Пример #4
0
        public static bool CheckButtonDown(string ID, bool pulse = false, bool hold = false, bool toggle = false)
        {
            if (pulse && hold)
            {
                throw new Exception("You can't pulse ot amd tell it to be held");
            }

            if (!_keybindings.ContainsKey(ID))
            {
                throw new Exception("Invalid Key Binding ID");
            }

            bool ret = true;

            _tempbinding = (Keybinding)_keybindings[ID];

            if (pulse && !_tempbinding.Pulse || !pulse)
            {
                foreach (string st in _tempbinding.Keys)
                {
                    if (st == "shift")
                    {
                        ret = Shift;
                    }
                    if (st == "ctrl")
                    {
                        ret = Control;
                    }
                    if (st.Length == 1)
                    {
                        if (lowercase.ContainsValue(st[0]))
                        {
                            ret = Keb.IsKeyDown(lowercase.FirstOrDefault(x => x.Value == st[0]).Key);
                        }
                    }
                    if (st == "caps")
                    {
                        ret = Keb.IsKeyDown(Keys.CapsLock);
                    }
                    if (st == "tab")
                    {
                        ret = Keb.IsKeyDown(Keys.Tab);
                    }
                    if (st == "alt")
                    {
                        ret = Alt;
                    }
                    if (st == "del")
                    {
                        ret = Keb.IsKeyDown(Keys.Delete);
                    }
                    if (st == "enter")
                    {
                        ret = Keb.IsKeyDown(Keys.Enter);
                    }
                    if (st == "back")
                    {
                        ret = Keb.IsKeyDown(Keys.Back);
                    }
                    if (st == "up")
                    {
                        ret = Keb.IsKeyDown(Keys.Up);
                    }
                    if (st == "left")
                    {
                        ret = Keb.IsKeyDown(Keys.Left);
                    }
                    if (st == "right")
                    {
                        ret = Keb.IsKeyDown(Keys.Right);
                    }
                    if (st == "down")
                    {
                        ret = Keb.IsKeyDown(Keys.Down);
                    }
                    if (st == "pgUp")
                    {
                        ret = Keb.IsKeyDown(Keys.PageUp);
                    }
                    if (st == "pgDn")
                    {
                        ret = Keb.IsKeyDown(Keys.PageDown);
                    }
                    if (st == "ins")
                    {
                        ret = Keb.IsKeyDown(Keys.Insert);
                    }
                    if (st == "home")
                    {
                        ret = Keb.IsKeyDown(Keys.Home);
                    }
                    if (st == "end")
                    {
                        ret = Keb.IsKeyDown(Keys.End);
                    }
                    if (st == "esc")
                    {
                        ret = Keb.IsKeyDown(Keys.Escape);
                    }
                    if (st == "f1")
                    {
                        ret = Keb.IsKeyDown(Keys.F1);
                    }
                    if (st == "f2")
                    {
                        ret = Keb.IsKeyDown(Keys.F2);
                    }
                    if (st == "f3")
                    {
                        ret = Keb.IsKeyDown(Keys.F3);
                    }
                    if (st == "f4")
                    {
                        ret = Keb.IsKeyDown(Keys.F4);
                    }
                    if (st == "f5")
                    {
                        ret = Keb.IsKeyDown(Keys.F5);
                    }
                    if (st == "f6")
                    {
                        ret = Keb.IsKeyDown(Keys.F6);
                    }
                    if (st == "f7")
                    {
                        ret = Keb.IsKeyDown(Keys.F7);
                    }
                    if (st == "f8")
                    {
                        ret = Keb.IsKeyDown(Keys.F8);
                    }
                    if (st == "f9")
                    {
                        ret = Keb.IsKeyDown(Keys.F9);
                    }
                    if (st == "f10")
                    {
                        ret = Keb.IsKeyDown(Keys.F10);
                    }
                    if (st == "f11")
                    {
                        ret = Keb.IsKeyDown(Keys.F11);
                    }
                    if (st == "f12")
                    {
                        ret = Keb.IsKeyDown(Keys.F12);
                    }
                    if (st == "prntScr")
                    {
                        ret = Keb.IsKeyDown(Keys.PrintScreen);
                    }
                    if (st == "mou1")
                    {
                        ret = Mou.LeftButton == ButtonState.Pressed;
                    }
                    if (st == "mou2")
                    {
                        ret = Mou.RightButton == ButtonState.Pressed;
                    }
                    if (st == "mou3")
                    {
                        ret = Mou.MiddleButton == ButtonState.Pressed;
                    }
                    if (!ret)
                    {
                        return(ret);
                    }
                }
                if (ret)
                {
                    if (pulse)
                    {
                        _tempbinding.Pulse = true;
                    }
                    if (hold)
                    {
                        _tempbinding.Held = true;
                    }
                    if (toggle && !_tempbinding.TogglePulse)
                    {
                        _tempbinding.Toggle = !_tempbinding.Toggle;
                    }
                }
            }
            else
            {
                ret = false;
            }
            if (pulse || hold || toggle && !_tempbinding.TogglePulse)
            {
                if (toggle && !_tempbinding.TogglePulse)
                {
                    _tempbinding.TogglePulse = true;
                }
                _keybindings[ID] = _tempbinding;
            }
            return(ret);
        }
Пример #5
0
 public static bool isBeingHeld(string ID)
 {
     _tempbinding = (Keybinding)_keybindings[ID];
     return(_tempbinding.Held);
 }