Example #1
0
        protected void addProcessKeyAction(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;

            processKeyActions.Add(keyAction, keyBundle);
        }
Example #2
0
        public KeyBundle(KeyCodes effectiveKey, KeyCodes?mod1 = null, KeyCodes?mod2 = null)
        {
            this.effectiveKey = effectiveKey;

            this.mod1 = mod1;
            this.mod2 = mod2;

            if (mod1 == null)
            {
                if (mod2 != null)
                {
                    this.mod1 = mod1;
                    this.mod2 = mod2;
                    throw new ArgumentException();
                }
            }
            else
            {
                if (mod2 != null)
                {
                    //this.mod2 = mod2;
                    if (mod1 > mod2)
                    {
                        this.mod1 = mod2;
                        this.mod2 = mod1;
                    }
                }
            }
        }
Example #3
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);
        }
Example #4
0
 public KeyBundle(List <KeyCodes> list)
 {
     effectiveKey = mod1 = mod2 = null;
     for (int i = list.Count - 1; i >= 0; i--)
     //for (int i = 0; i < list.Count; i++)
     {
         if (effectiveKey == null)
         {
             effectiveKey = list.ElementAt(i);
         }
         else if (mod1 == null)
         {
             mod1 = list.ElementAt(i);
         }
         else if (mod2 == null)
         {
             mod2 = list.ElementAt(i);
         }
     }
 }
Example #5
0
 public bool CheckMouseDown(KeyCodes?keycodes)
 {
     if (keycodes == KeyCodes.LeftClick)
     {
         return(newMouseState.LeftButton == ButtonState.Pressed);
     }
     else if (keycodes == KeyCodes.RightClick)
     {
         return(newMouseState.RightButton == ButtonState.Pressed);
     }
     else if (keycodes == KeyCodes.MiddleClick)
     {
         return(newMouseState.MiddleButton == ButtonState.Pressed);
     }
     else if (keycodes == KeyCodes.BackClick)
     {
         return(newMouseState.XButton1 == ButtonState.Pressed);
     }
     else if (keycodes == KeyCodes.ForwardClick)
     {
         return(newMouseState.XButton2 == ButtonState.Pressed);
     }
     return(false);
 }
Example #6
0
		private static bool KeyCodes_firesKeyPressEvent(KeyCodes keyCode,
			KeyCodes? opt_heldKeyCode = null, bool opt_shiftKey = false,
			bool opt_ctrlKey = false, bool opt_altKey = false, bool opt_metaKey = false)
		{
			if (!goog.userAgent.IE && !goog.userAgent.EDGE &&
				!(goog.userAgent.WEBKIT && goog.userAgent.isVersionOrHigher("525"))) {
				return true;
			}

			if (goog.userAgent.MAC && opt_altKey) {
				return goog.events.KeyCodes_isCharacterKey(keyCode);
			}

			// Alt but not AltGr which is represented as Alt+Ctrl.
			if (opt_altKey && !opt_ctrlKey) {
				return false;
			}

			// Saves Ctrl or Alt + key for IE and WebKit 525+, which won't fire keypress.
			// Non-IE browsers and WebKit prior to 525 won't get this far so no need to
			// check the user agent.
			if (opt_heldKeyCode.HasValue) {
				opt_heldKeyCode = goog.events.KeyCodes_normalizeKeyCode(opt_heldKeyCode.Value);
			}
			var heldKeyIsModifier = opt_heldKeyCode == goog.events.KeyCodes.CTRL ||
				opt_heldKeyCode == goog.events.KeyCodes.ALT ||
				goog.userAgent.MAC && opt_heldKeyCode == goog.events.KeyCodes.META;
			// The Shift key blocks keypresses on Mac iff accompanied by another modifier.
			var modifiedShiftKey = opt_heldKeyCode == goog.events.KeyCodes.SHIFT &&
				(opt_ctrlKey || opt_metaKey);
			if ((!opt_shiftKey || goog.userAgent.MAC) && heldKeyIsModifier ||
				goog.userAgent.MAC && modifiedShiftKey) {
				return false;
			}

			// Some keys with Ctrl/Shift do not issue keypress in WEBKIT.
			if ((goog.userAgent.WEBKIT || goog.userAgent.EDGE) && opt_ctrlKey &&
				opt_shiftKey) {
				switch (keyCode) {
				case goog.events.KeyCodes.BACKSLASH:
				case goog.events.KeyCodes.OPEN_SQUARE_BRACKET:
				case goog.events.KeyCodes.CLOSE_SQUARE_BRACKET:
				case goog.events.KeyCodes.TILDE:
				case goog.events.KeyCodes.SEMICOLON:
				case goog.events.KeyCodes.DASH:
				case goog.events.KeyCodes.EQUALS:
				case goog.events.KeyCodes.COMMA:
				case goog.events.KeyCodes.PERIOD:
				case goog.events.KeyCodes.SLASH:
				//case goog.events.KeyCodes.APOSTROPHE:
				case goog.events.KeyCodes.SINGLE_QUOTE:
					return false;
				}
			}

			// When Ctrl+<somekey> is held in IE, it only fires a keypress once, but it
			// continues to fire keydown events as the event repeats.
			if (goog.userAgent.IE && opt_ctrlKey && opt_heldKeyCode == keyCode) {
				return false;
			}

			switch (keyCode) {
			case goog.events.KeyCodes.ENTER:
				return true;
			case goog.events.KeyCodes.ESC:
				return !(goog.userAgent.WEBKIT || goog.userAgent.EDGE);
			}

			return goog.events.KeyCodes_isCharacterKey(keyCode);
		}
 public KeyBundle(List<KeyCodes> list)
 {
     effectiveKey = mod1 = mod2 = null;
     for (int i = list.Count - 1; i >= 0; i--)
     //for (int i = 0; i < list.Count; i++)
     {
         if (effectiveKey == null) effectiveKey = list.ElementAt(i);
         else if (mod1 == null) mod1 = list.ElementAt(i);
         else if (mod2 == null) mod2 = list.ElementAt(i);
     }
 }
        public KeyBundle(KeyCodes effectiveKey, KeyCodes? mod1 = null, KeyCodes? mod2 = null)
        {
            this.effectiveKey = effectiveKey;

            this.mod1 = mod1;
            this.mod2 = mod2;

            if (mod1 == null)
            {
                if (mod2 != null) { this.mod1 = mod1; this.mod2 = mod2; throw new ArgumentException(); }

            }
            else
            {
                if (mod2 != null)
                {
                    //this.mod2 = mod2;
                    if (mod1 > mod2)
                    {
                        this.mod1 = mod2;
                        this.mod2 = mod1;
                    }
                }
            }
        }
Example #9
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
                }
            }
        }