Ejemplo n.º 1
0
        /// <summary>
        /// Called by CryEngine. Do not call directly.
        /// </summary>
        public override bool OnInputEvent(SInputEvent e)
        {
            if (e.deviceType == EInputDeviceType.eIDT_Keyboard)
            {
                if (e.state == EInputState.eIS_Down)
                {
                    SInputEventExtentions.KeyDownLog [e.keyId] = true;
                }
                if (e.state == EInputState.eIS_Released)
                {
                    SInputEventExtentions.KeyDownLog [e.keyId] = false;
                }

                if (e.KeyDown(EKeyId.eKI_LShift))
                {
                    _lShiftDown = true;
                }
                if (e.KeyUp(EKeyId.eKI_LShift))
                {
                    _lShiftDown = false;
                }
                if (e.KeyDown(EKeyId.eKI_RShift))
                {
                    _rShiftDown = true;
                }
                if (e.KeyUp(EKeyId.eKI_RShift))
                {
                    _rShiftDown = false;
                }

                // Preprocess keyName to contain valid Chars
                if (e.keyId == EKeyId.eKI_Space)
                {
                    e.keyName.key = " ";
                }
                if (e.keyName.key.Length == 1)
                {
                    if (ShiftDown)
                    {
                        e.keyName.key = e.keyName.key.ToUpper();
                    }
                    if (ShiftDown && Char.IsDigit(e.keyName.key[0]))
                    {
                        e.keyName.key = "=!\"§$%&/()".Substring(e.keyName.key[0] - '0', 1);
                    }
                }
                else
                {
                    string res;
                    e.keyName.key = _charByDescription.TryGetValue(e.keyName.key, out res) ? res : string.Empty;
                }

                if (OnKey != null)
                {
                    OnKey(e);
                }
            }
            else if (e.deviceType == EInputDeviceType.eIDT_Gamepad)
            {
                // Set keyName.key = string.Empty to avoid showing up gamepad
                // presses controller keys in text input forms
                e.keyName.key = string.Empty;

                if (e.state == EInputState.eIS_Down)
                {
                    SInputEventExtentions.KeyDownLog [e.keyId] = true;
                }
                if (e.state == EInputState.eIS_Released)
                {
                    SInputEventExtentions.KeyDownLog [e.keyId] = false;
                }
                if (e.state == EInputState.eIS_Changed)
                {
                    SInputEventExtentions.KeyInputValueLog [e.keyId] = e.value;
                }

                if (OnKey != null)
                {
                    OnKey(e);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Called by CryEngine. Do not call directly.
        /// </summary>
        public override bool OnInputEvent(SInputEvent e)
        {
            if (e.deviceType == EInputDeviceType.eIDT_Keyboard)
            {
                switch (e.state)
                {
                case EInputState.eIS_Down:
                    SInputEventExtensions.KeyDownLog[e.keyId] = true;
                    break;

                case EInputState.eIS_Released:
                    SInputEventExtensions.KeyDownLog[e.keyId] = false;
                    break;
                }

                if (e.KeyDown(EKeyId.eKI_LShift))
                {
                    _lShiftDown = true;
                }
                if (e.KeyUp(EKeyId.eKI_LShift))
                {
                    _lShiftDown = false;
                }
                if (e.KeyDown(EKeyId.eKI_RShift))
                {
                    _rShiftDown = true;
                }
                if (e.KeyUp(EKeyId.eKI_RShift))
                {
                    _rShiftDown = false;
                }

                // Preprocess keyName to contain valid Chars
                if (e.keyId == EKeyId.eKI_Space)
                {
                    e.keyName.key = " ";
                }

                if (e.keyName.key.Length == 1)
                {
                    if (ShiftDown)
                    {
                        e.keyName.key = e.keyName.key.ToUpper();
                    }

                    if (ShiftDown && Char.IsDigit(e.keyName.key[0]))
                    {
                        e.keyName.key = "=!\"§$%&/()".Substring(e.keyName.key[0] - '0', 1);
                    }
                }
                else
                {
                    string res;
                    e.keyName.key = _charByDescription.TryGetValue(e.keyName.key, out res) ? res : string.Empty;
                }

                if (OnKey != null)
                {
                    OnKey(e);
                }
            }
            else if (e.deviceType == EInputDeviceType.eIDT_Gamepad || e.deviceType == EInputDeviceType.eIDT_Mouse)
            {
                // Set keyName.key = string.Empty to avoid showing up gamepad
                // presses controller keys in text input forms
                e.keyName.key = string.Empty;

                switch (e.state)
                {
                case EInputState.eIS_Down:
                    SInputEventExtensions.KeyDownLog[e.keyId] = true;
                    break;

                case EInputState.eIS_Released:
                    SInputEventExtensions.KeyDownLog[e.keyId] = false;
                    break;

                case EInputState.eIS_Changed:
                    SInputEventExtensions.KeyInputValueLog[e.keyId] = e.value;
                    break;
                }

                if (OnKey != null)
                {
                    OnKey(e);
                }
            }
            else if (e.deviceType == EInputDeviceType.eIDT_EyeTracker)
            {
                if (e.keyId == EKeyId.eKI_EyeTracker_X)
                {
                    var axis = GetAxis("EyeTracker");
                    _axisByName["EyeTracker"] = new Vector2(e.value, axis != null ? axis.y : 0);
                }
                if (e.keyId == EKeyId.eKI_EyeTracker_Y)
                {
                    var axis = GetAxis("EyeTracker");
                    _axisByName["EyeTracker"] = new Vector2(axis != null ? axis.x : 0, e.value);
                }
            }
            return(false);
        }