Пример #1
0
        void updateKeyboardState()
        {
            // dont process if we have no focused text element
            if (_keyboardFocusElement == null)
            {
                return;
            }

            var currentPressedKeys = Input.currentKeyboardState.GetPressedKeys();

            // keys down
            for (var i = 0; i < currentPressedKeys.Length; i++)
            {
                var key = currentPressedKeys[i];
                if (!_lastPressedKeys.contains(key))
                {
                    _keyboardFocusElement.keyDown(key);

                    // if alt isnt pressed we will call keyPressed
                    if (!InputUtils.isAltDown())
                    {
                        var c = key.getChar();
                        if (c.HasValue)
                        {
                            clearKeyRepeatTimer();
                            _keyboardFocusElement.keyPressed(key, c.Value);

                            // if we dont have a control key pressed setup a repeat timer for the key
                            if (!InputUtils.isControlDown())
                            {
                                _repeatKey      = key;
                                _keyRepeatTimer = Core.schedule(_keyRepeatTime, true, this, t =>
                                {
                                    var self = t.context as Stage;
                                    if (self._keyboardFocusElement != null)
                                    {
                                        self._keyboardFocusElement.keyPressed(_repeatKey, _repeatKey.getChar().Value);
                                    }
                                });
                            }
                        }
                    }
                }
            }

            // keys released
            for (var i = 0; i < _lastPressedKeys.Length; i++)
            {
                var key = _lastPressedKeys[i];
                if (!currentPressedKeys.contains(key))
                {
                    _keyboardFocusElement.keyReleased(key);
                    clearKeyRepeatTimer();
                }
            }

            _lastPressedKeys = currentPressedKeys;
        }