Exemplo n.º 1
0
        public char?GetCharExclusiveJustDownAndSwallow(InputConsumer ic)
        {
            var shift = IsKeyDown(SKeys.ShiftAny);

            if (IsKeyExclusiveJustDown(SKeys.Space))
            {
                SwallowKey(SKeys.Space, ic); return(' ');
            }

            for (SKeys chr = SKeys.A; chr < SKeys.Z; chr++)
            {
                if (IsKeyExclusiveJustDown(chr))
                {
                    SwallowKey(chr, ic); return((char)(chr - SKeys.A + (shift ? 'A' : 'a')));
                }
            }

            if (IsKeyExclusiveJustDown(SKeys.D0))
            {
                SwallowKey(SKeys.D0, ic); return('0');
            }
            if (IsKeyExclusiveJustDown(SKeys.D1))
            {
                SwallowKey(SKeys.D1, ic); return('1');
            }
            if (IsKeyExclusiveJustDown(SKeys.D2))
            {
                SwallowKey(SKeys.D2, ic); return('2');
            }
            if (IsKeyExclusiveJustDown(SKeys.D3))
            {
                SwallowKey(SKeys.D3, ic); return('3');
            }
            if (IsKeyExclusiveJustDown(SKeys.D4))
            {
                SwallowKey(SKeys.D4, ic); return('4');
            }
            if (IsKeyExclusiveJustDown(SKeys.D5))
            {
                SwallowKey(SKeys.D5, ic); return('5');
            }
            if (IsKeyExclusiveJustDown(SKeys.D6))
            {
                SwallowKey(SKeys.D6, ic); return('6');
            }
            if (IsKeyExclusiveJustDown(SKeys.D7))
            {
                SwallowKey(SKeys.D7, ic); return('7');
            }
            if (IsKeyExclusiveJustDown(SKeys.D8))
            {
                SwallowKey(SKeys.D8, ic); return('8');
            }
            if (IsKeyExclusiveJustDown(SKeys.D9))
            {
                SwallowKey(SKeys.D9, ic); return('9');
            }

            return(null);
        }
Exemplo n.º 2
0
        private string FormatKey(SKeys k)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (k)
            {
            case SKeys.D0:
            case SKeys.D1:
            case SKeys.D2:
            case SKeys.D3:
            case SKeys.D4:
            case SKeys.D5:
            case SKeys.D6:
            case SKeys.D7:
            case SKeys.D8:
            case SKeys.D9:
                return(k.ToString().Substring(1));

            case SKeys.AndroidBack:
                return("Back");

            case SKeys.AndroidMenu:
                return("Menu");

            default:
                return(k.ToString());
            }
        }
Exemplo n.º 3
0
 public void SwallowKey(SKeys s, InputConsumer ic)
 {
     if (_consumedKeyEvts == null)
     {
         _consumedKeyEvts = new List <Tuple <SKeys, InputConsumer> >();
     }
     _consumedKeyEvts.Add(Tuple.Create(s, ic));
 }
Exemplo n.º 4
0
        public ButtonState Get(SKeys keys)
        {
            if ((keys & SKeys.MouseFlag) != SKeys.MouseFlag)
            {
                throw new ArgumentException("Invalid SKeys type");
            }

            return _buttonStates[keys - SKeys.MouseOffset];
        }
Exemplo n.º 5
0
        public bool IsKeyDown(SKeys key)
        {
            bool v;

            if (currentKeyState.TryGetValue(key, out v))
            {
                return(v);
            }
            else
            {
                v = IsKeyDown(key, Keyboard, GamePad);
                currentKeyState.Add(key, v);
                return(v);
            }
        }
Exemplo n.º 6
0
        public bool IsKeyExclusiveJustDown(SKeys key)
        {
            if (_consumedKeyEvts != null && _consumedKeyEvts.Any(e => e.Item1 == key))
            {
                return(false);
            }

            bool v;

            if (currentKeyState.TryGetValue(key, out v))
            {
                return(v && !lastKeyState[key]);
            }
            else
            {
                v = IsKeyDown(key, Keyboard, GamePad);
                currentKeyState.Add(key, v);
                lastKeyState.Add(key, v);
                return(false);
            }
        }
Exemplo n.º 7
0
        private static bool IsKeyDown(SKeys key, KeyboardState ks, GamePadState gs)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (key)
            {
            case SKeys.ShiftAny:
                return(ks.IsKeyDown(Keys.LeftShift) || ks.IsKeyDown(Keys.RightShift));

            case SKeys.ControlAny:
                return(ks.IsKeyDown(Keys.LeftControl) || ks.IsKeyDown(Keys.RightControl));

            case SKeys.AltAny:
                return(ks.IsKeyDown(Keys.LeftAlt) || ks.IsKeyDown(Keys.RightAlt));

            case SKeys.AndroidBack:
                return(gs.Buttons.Back == ButtonState.Pressed);

            default:
                return(ks.IsKeyDown((Keys)key));
            }
        }
Exemplo n.º 8
0
 public bool IsShortcutExclusiveJustPressed(KeyModifier mod, SKeys key)
 {
     return(IsModifierDown(mod) && IsKeyExclusiveJustDown(key));
 }
Exemplo n.º 9
0
        public static void AddPush(string parentIdent, string ident, ILifetimeObject owner, SKeys actionkey, KeyModifier mod, Action <DebugListener> listenerEvent = null)
        {
            var upperIdent = ident.ToUpper();

            if (listeners.ContainsKey(upperIdent))
            {
                listeners.Remove(upperIdent);
            }

            var result = new DebugListener(parentIdent, ident, owner, actionkey, mod, DebugListener.DebugListenerType.Push);

            if (listenerEvent != null)
            {
                result.SetEvent(listenerEvent);
            }
            listeners.Add(upperIdent, result);
        }
Exemplo n.º 10
0
        public static void AddSwitch(string parentIdent, string ident, ILifetimeObject owner, SKeys actionkey, KeyModifier mod, bool initial)
        {
            var upperIdent = ident.ToUpper();

            if (listeners.ContainsKey(upperIdent))
            {
                initial = listeners[upperIdent].SelfActive;
                listeners.Remove(upperIdent);
            }

            var result = new DebugListener(parentIdent, ident, owner, actionkey, mod, DebugListener.DebugListenerType.Switch);

            result.Set(initial);
            listeners.Add(upperIdent, result);
        }
Exemplo n.º 11
0
 public bool IsUp(SKeys key)
 {
     return Get(key) == ButtonState.Up;
 }
Exemplo n.º 12
0
 public bool IsReleased(SKeys key)
 {
     return Get(key) == ButtonState.Released;
 }
Exemplo n.º 13
0
 public bool IsPressed(SKeys key)
 {
     return Get(key) == ButtonState.Pressed;
 }
Exemplo n.º 14
0
 public bool IsDown(SKeys key)
 {
     return Get(key) == ButtonState.Down;
 }
Exemplo n.º 15
0
 public bool IsShortcutPressed(KeyModifier mod, SKeys key)
 {
     return(IsModifierDown(mod) && IsKeyDown(key));
 }
Exemplo n.º 16
0
 public static KeyCombinationList C(SKeys key1, SKeys key2, SKeys key3)
 {
     return(new KeyCombinationList(new KeyCombination(key1, KeyModifier.None), new KeyCombination(key2, KeyModifier.None), new KeyCombination(key3, KeyModifier.None)));
 }
Exemplo n.º 17
0
 public static KeyCombinationList C(SKeys key1, KeyModifier mod1, SKeys key2, KeyModifier mod2)
 {
     return(new KeyCombinationList(new KeyCombination(key1, mod1), new KeyCombination(key2, mod2)));
 }
Exemplo n.º 18
0
 public KeyCombination(SKeys k, KeyModifier m)
 {
     Key = k;
     Mod = m;
 }
Exemplo n.º 19
0
 public DebugListener(string parentIdent, string ident, ILifetimeObject owner, SKeys actionkey, KeyModifier mod, DebugListenerType debugtype)
 {
     ParentIdentifier = parentIdent;
     Identifier       = ident;
     keys             = new KeyCombinationList(new KeyCombination(actionkey, mod));
     Type             = debugtype;
     Owner            = owner;
 }