コード例 #1
0
        public void addGlobalKeyAction(String name, KeyCodes k1, KeyCodes?k2 = null, KeyCodes?k3 = null,
                                       Action OnPress = null, Action OnRelease = null, Action OnHold = null)
        {
            KeyBundle keyBundle;

            if (k2 == null)
            {
                keyBundle = new KeyBundle(k1);
            }
            else if (k3 == null)
            {
                keyBundle = new KeyBundle((KeyCodes)k2, k1);
            }
            else
            {
                keyBundle = new KeyBundle((KeyCodes)k3, (KeyCodes)k2, k1);
            }

            var keyAction = new KeyAction(name, OnPress, new HashSet <KeyBundle>()
            {
                keyBundle
            });

            keyAction.releaseAction = OnRelease;
            keyAction.holdAction    = OnHold;

            Keybinds.Add(keyBundle, keyAction);
        }
コード例 #2
0
        public void Add(string name, HashSet <KeyBundle> bundles, Action action)
        {
            KeyAction ka = new KeyAction(name, action, bundles);

            foreach (KeyBundle b in bundles)
            {
                Keybinds.Add(b, ka);
            }
        }
コード例 #3
0
        public void Add(string name, KeyBundle bundle, Action action, Action holdAction = null)
        {
            KeyAction ka = new KeyAction(name, action, new HashSet <KeyBundle>()
            {
                bundle
            });

            Keybinds.Add(bundle, ka);
        }
コード例 #4
0
        public void TryAction()
        {
            KeyBundle kb = new KeyBundle(PressedKeys);
            string    m1 = "none";
            string    m2 = "none";

            if (kb.mod1 != null)
            {
                m1 = ((KeyCodes)kb.mod1).ToString();
            }
            if (kb.mod2 != null)
            {
                m2 = ((KeyCodes)kb.mod2).ToString();
            }

            //Console.WriteLine("ex: {0}\t\tmod1: {1}\t\tmod2: {2}", kb.effectiveKey, m1, m2);
            //Console.WriteLine("ex: {0}\t\tmod1: {1}\t\tmod2: {2} \t\t extra: {3}", PressedKeys.ElementAt(0), PressedKeys.ElementAt(1), PressedKeys.ElementAt(2), PressedKeys.ElementAt(3));
            //Console.WriteLine("ex: {0}", PressedKeys.Count);


            if (!Keybinds.ContainsKey(kb))
            {
                KeyCodes?temp = null;

                if (kb.mod2 != null)
                {
                    temp    = kb.mod2;
                    kb.mod2 = null;
                }

                if (!Keybinds.ContainsKey(kb))
                {
                    if (kb.mod1 != null)
                    {
                        kb.mod1 = temp;
                    }
                    if (!Keybinds.ContainsKey(kb))
                    {
                        kb.mod1 = null;
                        if (!Keybinds.ContainsKey(kb))
                        {
                            return;
                        }
                    }
                }
            }

            KeyAction ka = Keybinds[kb];

            if (ka != null)
            {
                if (MouseInGameBox ||
                    (kb.effectiveKey != KeyCodes.LeftClick && kb.effectiveKey != KeyCodes.RightClick &&
                     kb.effectiveKey != KeyCodes.MiddleClick))
                {
                    if (ka.pressAction != null)
                    {
                        ka.pressAction();
                    }
                    //if (!PressedBundles.ContainsKey(kb))
                    PressedBundles.Add(kb, ka); //exception
                }
            }
        }