Ejemplo n.º 1
0
 // Update is called once per frame
 void Update()
 {
     if (Input.anyKey)
     {
         foreach (KeyCode keyCode in Enum.GetValues(typeof(KeyCode)))
         {
             if (Input.GetKey(keyCode))
             {
                 OnKey?.Invoke(keyCode);
                 break;
             }
         }
     }
     if (Input.anyKeyDown)
     {
         foreach (KeyCode keyCode in Enum.GetValues(typeof(KeyCode)))
         {
             if (Input.GetKey(keyCode))
             {
                 codes.Add(keyCode);
                 OnKeyDown?.Invoke(keyCode);
                 break;
             }
         }
     }
     foreach (KeyCode keyCode in codes)
     {
         if (Input.GetKeyUp(keyCode))
         {
             OnKeyUp?.Invoke(keyCode);
             break;
         }
     }
 }
Ejemplo n.º 2
0
        private void Update()
        {
            if (!IsTracking)
            {
                return;
            }

            bool isKey     = Input.GetKey(key);
            bool isKeyDown = Input.GetKeyDown(key);
            bool isKeyUp   = Input.GetKeyUp(key);

            if (isKey)
            {
                OnKey?.Invoke();
            }

            if (isKeyDown)
            {
                OnKeyDown?.Invoke();
            }

            if (isKeyUp)
            {
                OnKeyUp?.Invoke();
            }
        }
Ejemplo n.º 3
0
        private void InputSystemOnKeyChange(Input.IInput obj)
        {
            Dispatcher.Invoke(() => {
                SetBlock(_elmGrid[(int)(Math.Round(obj.BlockPos.X + 1)), (int)(Math.Round(-obj.BlockPos.Y + 1))]);

                if (Math.Abs(obj.CharPos.X) > 0.1f || Math.Abs(obj.CharPos.Y) > 0.1f)
                {
                    var c = _activeElement.GetStr((int)obj.CharPos.X, (int)-obj.CharPos.Y);
                    OnKey?.Invoke(c);
                }
            });
        }
Ejemplo n.º 4
0
 void sendEvent(KeyCode keycode, KeyboardEventType evType)
 {
     if (evType == KeyboardEventType.keyDown)
     {
         OnKey.Invoke(keycode);
     }
     if (evType == KeyboardEventType.KeyUp)
     {
         OnKeyUp.Invoke(keycode);
     }
     if (evType == KeyboardEventType.down)
     {
         OnKeyDown.Invoke(keycode);
     }
 }
Ejemplo n.º 5
0
        protected void UpdateKeyStatus(Key key, bool down)
        {
            var keyIndex = (short)key;

            // If it was down, and still is - then it's held.
            if (_keys[keyIndex] && down)
            {
                OnKey.Invoke(key, KeyStatus.Held);
            }

            // If it was down, but no longer is - it was let go.
            if (_keys[keyIndex] && !down)
            {
                OnKey.Invoke(key, KeyStatus.Up);
            }

            // If it was up, and now is down - it was pressed.
            if (!_keys[keyIndex] && down)
            {
                OnKey.Invoke(key, KeyStatus.Down);
            }
            _keys[keyIndex] = down;
        }
Ejemplo n.º 6
0
        public static void Run()
        {
            try
            {
                Console.Clear();

                while (_running)
                {
                    ConsoleEx.WrapInOutputLock(() => {
                        Console.CursorVisible = false;
                        Console.SetCursorPosition(0, 0);
                        ConsoleEx.WriteLineEnh(SetTitle.Invoke().FixedWidthEnh(ConsoleEx.WindowWidth - 12) + "    " + DateTime.Now.ToStringHH24mmss());
                        ConsoleEx.WriteLineEnh(SetKeysHelp.Invoke().FixedWidthEnh(ConsoleEx.WindowWidth - 8 /*16*/) + "  " + "- *Q*U|T" /*$" * R*estart - *Q*U|T"*/);

                        OnRefresh?.Invoke();
                        Console.CursorVisible = true;
                    });

                    var keyInfo = ConsoleEx.ReadKeyWithTimeout(RefreshInterval);
                    if (keyInfo == null)
                    {
                        continue;
                    }

                    if (keyInfo.Value.KeyChar != 'Q' && keyInfo.Value.KeyChar != '|')
                    {
                        OnKey?.Invoke(keyInfo.Value.KeyChar.ToString());
                    }

                    HandleStandardKey(keyInfo);
                }
            }
            finally
            {
                _cts.Cancel();
            }
        }
Ejemplo n.º 7
0
        void Update()
        {
            if (!IsTracking)
            {
                return;
            }

            var isKey     = UnityEngine.Input.GetKey(key);
            var isKeyDown = UnityEngine.Input.GetKeyDown(key);
            var isKeyUp   = UnityEngine.Input.GetKeyUp(key);

            if (isKey)
            {
                OnKey?.Invoke();
            }
            if (isKeyDown)
            {
                OnKeyDown?.Invoke();
            }
            if (isKeyUp)
            {
                OnKeyUp?.Invoke();
            }
        }
Ejemplo n.º 8
0
        private static void OnInput(SInputEvent nativeEvent)
        {
            var managedEvent = new InputEvent(nativeEvent);

            if (managedEvent.DeviceType == InputDeviceType.Keyboard)
            {
                switch (managedEvent.State)
                {
                case InputState.Down:
                    SetKeyStateDown(managedEvent.KeyId, true);
                    break;

                case InputState.Released:
                    SetKeyStateDown(managedEvent.KeyId, false);
                    break;
                }

                if (KeyDown(KeyId.LShift))
                {
                    _lShiftDown = true;
                }
                if (KeyUp(KeyId.LShift))
                {
                    _lShiftDown = false;
                }
                if (KeyDown(KeyId.RShift))
                {
                    _rShiftDown = true;
                }
                if (KeyUp(KeyId.RShift))
                {
                    _rShiftDown = false;
                }

                // Preprocess keyName to contain valid Chars
                if (managedEvent.KeyId == KeyId.Space)
                {
                    managedEvent.KeyName = " ";
                }

                if (managedEvent.KeyName.Length == 1)
                {
                    if (ShiftDown)
                    {
                        managedEvent.KeyName = managedEvent.KeyName.ToUpper();
                    }

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

                OnKey?.Invoke(managedEvent);
            }
            else if (managedEvent.DeviceType == InputDeviceType.Gamepad || managedEvent.DeviceType == InputDeviceType.Mouse)
            {
                // Set keyName.key = string.Empty to avoid showing up gamepad
                // presses controller keys in text input forms
                managedEvent.KeyName = string.Empty;

                switch (managedEvent.State)
                {
                case InputState.Down:
                    SetKeyStateDown(managedEvent.KeyId, true);
                    break;

                case InputState.Released:
                    SetKeyStateDown(managedEvent.KeyId, false);
                    break;

                case InputState.Changed:
                    SetKeyStateValue(managedEvent.KeyId, managedEvent.Value);
                    break;
                }

                if (OnKey != null)
                {
                    OnKey(managedEvent);
                }
            }
            else if (managedEvent.DeviceType == InputDeviceType.EyeTracker)
            {
                if (managedEvent.KeyId == KeyId.EyeTracker_X)
                {
                    var axis = GetAxis("EyeTracker");
                    _axisByName["EyeTracker"] = new Vector2(managedEvent.Value, axis != null ? axis.y : 0);
                }
                if (managedEvent.KeyId == KeyId.EyeTracker_Y)
                {
                    var axis = GetAxis("EyeTracker");
                    _axisByName["EyeTracker"] = new Vector2(axis != null ? axis.x : 0, managedEvent.Value);
                }
            }
        }
Ejemplo n.º 9
0
        private void Update()
        {
            if (SDL_Installed && !SDL_Initialized)
            {
                InitSDL();
            }
            if (!SDL_Initialized)
            {
                return;
            }

            SDL.SDL_Event e;

            while (SDL.SDL_PollEvent(out e) > 0)
            {
                switch (e.type)
                {
                case SDL.SDL_EventType.SDL_KEYDOWN:
                    OnKey?.Invoke(e, true);
                    break;

                case SDL.SDL_EventType.SDL_KEYUP:
                    OnKey?.Invoke(e, false);
                    break;

                case SDL.SDL_EventType.SDL_CONTROLLERAXISMOTION:
                    OnAxisMotion?.Invoke(e);
                    break;

                case SDL.SDL_EventType.SDL_CONTROLLERBUTTONDOWN:
                    OnButton?.Invoke(e, true);
                    break;

                case SDL.SDL_EventType.SDL_CONTROLLERBUTTONUP:
                    OnButton?.Invoke(e, false);
                    break;

                case SDL.SDL_EventType.SDL_CONTROLLERDEVICEADDED:
                    Controller.AddDevice(e.cdevice.which);
                    OnDeviceAdded?.Invoke(e);
                    break;

                case SDL.SDL_EventType.SDL_CONTROLLERDEVICEREMOVED:
                    Controller.RemoveDisconnected();
                    OnDeviceRemoved?.Invoke(e);
                    break;

                case SDL.SDL_EventType.SDL_CONTROLLERDEVICEREMAPPED:
                    OnDeviceRemapped?.Invoke(e);
                    break;

                case SDL.SDL_EventType.SDL_JOYAXISMOTION:
                    OnAxisMotion?.Invoke(e);
                    break;

                case SDL.SDL_EventType.SDL_JOYBALLMOTION:
                    OnBallMotion?.Invoke(e);
                    break;

                case SDL.SDL_EventType.SDL_JOYHATMOTION:
                    OnHatMotion?.Invoke(e);
                    break;

                case SDL.SDL_EventType.SDL_JOYBUTTONDOWN:
                    OnButton?.Invoke(e, true);
                    break;

                case SDL.SDL_EventType.SDL_JOYBUTTONUP:
                    OnButton?.Invoke(e, false);
                    break;

                case SDL.SDL_EventType.SDL_JOYDEVICEADDED:
                    Controller.AddDevice(e.jdevice.which);
                    OnDeviceAdded?.Invoke(e);
                    break;

                case SDL.SDL_EventType.SDL_JOYDEVICEREMOVED:
                    Controller.RemoveDisconnected();
                    OnDeviceRemoved?.Invoke(e);
                    break;

                default:
                    break;
                }
            }
        }
Ejemplo n.º 10
0
 private Input()
 {
     RootElement.OnKey       += (string key, bool isPressed) => { OnKey?.Invoke(key, isPressed); };
     RootElement.OnCharacter += (string character) => { OnCharacter?.Invoke(character); };
 }