Example #1
0
 public void Reset()
 {
     touchId         = -1;
     x               = 0;
     y               = 0;
     clickCount      = 0;
     button          = -1;
     keyCode         = Keys.None;
     keyName         = null;
     character       = '\0';
     modifiers       = 0;
     mouseWheelDelta = 0;
     lastClickTime   = 0;
     began           = false;
     target          = null;
     downTargets.Clear();
     lastRollOver   = null;
     clickCancelled = false;
     touchMonitors.Clear();
 }
Example #2
0
        private void HandleKeyEvents()
        {
            Keys[] keys = Keyboard.GetState().GetPressedKeys();

            InputModifierFlags modifiers = 0;

            float currTime = Timers.time;
            int   cnt      = keys.Length;

            for (int i = 0; i < cnt; i++)
            {
                Keys key = keys[i];

                switch (key)
                {
                case Keys.LeftShift:
                    modifiers |= InputModifierFlags.LShift;
                    break;

                case Keys.RightShift:
                    modifiers |= InputModifierFlags.RShift;
                    break;

                case Keys.LeftAlt:
                    modifiers |= InputModifierFlags.LAlt;
                    break;

                case Keys.RightAlt:
                    modifiers |= InputModifierFlags.RAlt;
                    break;

                case Keys.LeftControl:
                    modifiers |= InputModifierFlags.LCtrl;
                    break;

                case Keys.RightControl:
                    modifiers |= InputModifierFlags.RCtrl;
                    break;

                case Keys.CapsLock:
                    modifiers |= InputModifierFlags.CapsLock;
                    break;

                case Keys.NumLock:
                    modifiers |= InputModifierFlags.NumLock;
                    break;
                }
            }

            if (_lastKeys != null)
            {
                cnt = _lastKeys.Length;
                for (int i = 0; i < cnt; i++)
                {
                    Keys key = _lastKeys[i];
                    if (Array.IndexOf(keys, key) == -1)
                    {
                        _lastKeyDownTime.Remove(key);
                    }
                }
            }

            _lastKeys = keys;

            cnt = keys.Length;
            for (int i = 0; i < cnt; i++)
            {
                Keys key = keys[i];

                float lastDownTime;
                if (_lastKeyDownTime.TryGetValue(key, out lastDownTime))
                {
                    if (currTime - lastDownTime < 0)
                    {
                        continue;
                    }

                    _lastKeyDownTime[key] = currTime + 0.05f;
                }
                else
                {
                    _lastKeyDownTime[key] = currTime + 0.5f;
                }

                _touchInfo.keyCode   = key;
                _touchInfo.keyName   = null;
                _touchInfo.modifiers = modifiers;

                //evt.keyName is not reliable, I parse it myself.
                if (key >= Keys.A && key <= Keys.Z)
                {
                    bool capsLock = (modifiers & InputModifierFlags.CapsLock) != 0;
                    if ((modifiers & InputModifierFlags.Shift) != 0)
                    {
                        capsLock = !capsLock;
                    }
                    if (capsLock)
                    {
                        _touchInfo.keyName = key.ToString();
                    }
                    else
                    {
                        _touchInfo.keyName = key.ToString().ToLower();
                    }
                }
                else
                {
                    if (_charByScanCode3.TryGetValue(key, out _touchInfo.keyName))
                    {
                        if (key == Keys.NumLock)
                        {
                            _touchInfo.keyName = null;
                        }
                    }
                    else if ((modifiers & InputModifierFlags.Shift) != 0)
                    {
                        if (!_charByScanCode2.TryGetValue(key, out _touchInfo.keyName))
                        {
                            _charByScanCode1.TryGetValue(key, out _touchInfo.keyName);
                        }
                    }
                    else
                    {
                        _charByScanCode1.TryGetValue(key, out _touchInfo.keyName);
                    }
                }

                _touchInfo.UpdateEvent();
                DisplayObject f = this.focus;
                if (f != null)
                {
                    f.BubbleEvent("onKeyDown", _touchInfo.evt);
                }
                else
                {
                    DispatchEvent("onKeyDown", _touchInfo.evt);
                }
            }
        }