/// <summary>
        /// Handles SDL2's KEYUP event.
        /// </summary>
        private void OnKeyUp(ref SDL_KeyboardEvent evt)
        {
            var window = Ultraviolet.GetPlatform().Windows.GetByID((int)evt.windowID);

            states[(int)evt.keysym.scancode].OnUp();

            OnButtonReleased(window, (Scancode)evt.keysym.scancode);
            OnKeyReleased(window, (Key)evt.keysym.keycode);
        }
Beispiel #2
0
        private void onKeyPressed(SDL_KeyboardEvent args)
        {
            if (args.repeat == 0)
            {
                this.currentState[args.keysym.scancode] = true;
            }

            this.pressedKeys.Add(args.keysym.sym);
        }
        /// <summary>
        /// 同时处理keydown和up事件
        /// </summary>
        /// <param name="keyboardEvent"></param>
        private static void HandleKeyboardEvent(SDL_KeyboardEvent keyboardEvent)
        {
            //SimpleInputSnapshot snapshot = _privateSnapshot;
            CefKeyEvent keyEvent = new CefKeyEvent();

            keyEvent.Modifiers      = GetModifiersFromSDL(keyboardEvent.keysym.mod);
            keyEvent.WindowsKeyCode = (int)(GetWindowsKeycodeFromSDLKeycode(keyboardEvent.keysym.scancode));
            keyEvent.NativeKeyCode  = (int)keyboardEvent.keysym.scancode;

            keyEvent.EventType = keyboardEvent.state == 0 ? CefKeyEventType.RawKeyDown:CefKeyEventType.KeyUp;
            _host.SendKeyEvent(keyEvent);
        }
        /// <summary>
        /// Handles SDL2's KEYDOWN event.
        /// </summary>
        private void OnKeyDown(ref SDL_KeyboardEvent evt)
        {
            var window = Ultraviolet.GetPlatform().Windows.GetByID((int)evt.windowID);
            var mods   = evt.keysym.mod;
            var ctrl   = (mods & SDL_Keymod.CTRL) != 0;
            var alt    = (mods & SDL_Keymod.ALT) != 0;
            var shift  = (mods & SDL_Keymod.SHIFT) != 0;
            var repeat = evt.repeat > 0;

            states[(int)evt.keysym.scancode].OnDown(repeat);

            if (!repeat)
            {
                OnButtonPressed(window, (Scancode)evt.keysym.scancode);
            }
            OnKeyPressed(window, (Key)evt.keysym.keycode, ctrl, alt, shift, repeat);
        }
Beispiel #5
0
            private KeyboardEventArgs ConvertKeyEvent(SDL_KeyboardEvent keyboardEvent)
            {
                KeyModifier modifier = ConvertModifier(keyboardEvent.KeySym.Modifier);
                Key         key      = ConvertKey(keyboardEvent.KeySym.Scancode);

                if (key != Key.None)
                {
                    return(new KeyboardEventArgs(key, modifier));
                }

                char keyChar = (char)keyboardEvent.KeySym.Keycode;

                if (keyChar != '.' && keyChar != ',' && (char.ToLower(keyChar) < 'a' || (int)char.ToLower(keyChar) > 'z') && (keyChar < '0' || keyChar > '9'))
                {
                    return(null);
                }
                return(new KeyboardEventArgs(char.ToUpper(keyChar), modifier));
            }
Beispiel #6
0
        private static void HandleKeyboardEvent(SDL_KeyboardEvent e)
        {
            var key       = MapKey(e.keysym.scancode);
            var modifiers = MapModifierKeys(e.keysym.mod);
            var isDown    = e.state == 1;

            InputState.ModifiersKeys = modifiers;
            InputState.HandleKeyboardEvent(key, isDown);

            if (isDown)
            {
                App.Instance.Window.OnKeyDown(key, modifiers);
            }
            else
            {
                App.Instance.Window.OnKeyUp(key, modifiers);
            }
        }
Beispiel #7
0
            private void HandleEventKeyboard(SDL_KeyboardEvent keyboardEvent)
            {
                KeyboardEventArgs args = ConvertKeyEvent(keyboardEvent);

                if (args == null)
                {
                    return;
                }

                switch (keyboardEvent.State)
                {
                case SDL_KeyState.SDL_PRESSED:
                    OnKeyDown?.Invoke(this, args);
                    return;

                case SDL_KeyState.SDL_RELEASED:
                    OnKeyUp?.Invoke(this, args);
                    return;
                }
            }
Beispiel #8
0
        private void UnityInputUpdate()
        {
            var oneOverScale = 1f / scale;

            //Finger/mouse handling
            if (UnityEngine.Application.isMobilePlatform)
            {
                var fingers = Lean.Touch.LeanTouch.GetFingers(true, false);

                foreach (var finger in fingers)
                {
                    var leftMouseDown  = finger.Down;
                    var leftMouseHeld  = finger.Set;
                    var leftMouseUp    = finger.Up;
                    var rightMouseDown = false;
                    var rightMouseHeld = false;
                    var rightMouseUp   = false;
                    var mouseMotion    = finger.ScreenPosition != finger.LastScreenPosition;

                    Mouse.Position.X = UnityEngine.Mathf.RoundToInt(finger.ScreenPosition.x * oneOverScale);
                    Mouse.Position.Y = UnityEngine.Mathf.RoundToInt((UnityEngine.Screen.height - finger.ScreenPosition.y) * oneOverScale);

                    SimulateMouse(leftMouseDown, leftMouseHeld, leftMouseUp, rightMouseDown, rightMouseHeld, rightMouseUp, mouseMotion);
                }
            }
            else
            {
                var leftMouseDown  = UnityEngine.Input.GetMouseButtonDown(0);
                var leftMouseHeld  = UnityEngine.Input.GetMouseButton(0);
                var leftMouseUp    = UnityEngine.Input.GetMouseButtonUp(0);
                var rightMouseDown = UnityEngine.Input.GetMouseButtonDown(1);
                var rightMouseHeld = UnityEngine.Input.GetMouseButton(1);
                var rightMouseUp   = UnityEngine.Input.GetMouseButtonUp(1);
                var mousePosition  = UnityEngine.Input.mousePosition;
                var mouseMotion    = mousePosition != lastMousePosition;
                lastMousePosition = mousePosition;

                if (Lean.Touch.LeanTouch.PointOverGui(mousePosition))
                {
                    Mouse.Position.X = 0;
                    Mouse.Position.Y = 0;
                    leftMouseDown    = false;
                    leftMouseHeld    = false;
                    leftMouseUp      = false;
                    rightMouseDown   = false;
                    rightMouseHeld   = false;
                    rightMouseUp     = false;
                }

                Mouse.Position.X = UnityEngine.Mathf.RoundToInt(mousePosition.x * oneOverScale);
                Mouse.Position.Y = UnityEngine.Mathf.RoundToInt((UnityEngine.Screen.height - mousePosition.y) * oneOverScale);

                SimulateMouse(leftMouseDown, leftMouseHeld, leftMouseUp, rightMouseDown, rightMouseHeld, rightMouseUp, mouseMotion);
            }

            //Keyboard handling
            var keymod = SDL.SDL_Keymod.KMOD_NONE;

            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftAlt))
            {
                keymod |= SDL_Keymod.KMOD_LALT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.RightAlt))
            {
                keymod |= SDL_Keymod.KMOD_RALT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftShift))
            {
                keymod |= SDL_Keymod.KMOD_LSHIFT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.RightShift))
            {
                keymod |= SDL_Keymod.KMOD_RSHIFT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftControl))
            {
                keymod |= SDL_Keymod.KMOD_LCTRL;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.RightControl))
            {
                keymod |= SDL_Keymod.KMOD_RCTRL;
            }
            foreach (var keyCode in _keyCodeEnumValues)
            {
                if (UnityEngine.Input.GetKeyDown(keyCode))
                {
                    var key = new SDL_KeyboardEvent()
                    {
                        keysym = new SDL_Keysym()
                        {
                            sym = (SDL_Keycode)keyCode, mod = keymod
                        }
                    };
                    Keyboard.OnKeyDown(key);

                    if (Plugin.ProcessHotkeys((int)key.keysym.sym, (int)key.keysym.mod, true))
                    {
                        _ignoreNextTextInput = false;

                        UIManager.KeyboardFocusControl?.InvokeKeyDown(key.keysym.sym, key.keysym.mod);

                        _scene.OnKeyDown(key);
                    }
                    else
                    {
                        _ignoreNextTextInput = true;
                    }
                }
                if (UnityEngine.Input.GetKeyUp(keyCode))
                {
                    var key = new SDL_KeyboardEvent()
                    {
                        keysym = new SDL_Keysym()
                        {
                            sym = (SDL_Keycode)keyCode
                        }
                    };
                    Keyboard.OnKeyUp(key);
                    UIManager.KeyboardFocusControl?.InvokeKeyUp(key.keysym.sym, key.keysym.mod);
                    _scene.OnKeyUp(key);
                }
            }

            //Input text handling
            if (UnityEngine.Application.isMobilePlatform)
            {
                var text = TouchScreenKeyboard?.text;
                if (_ignoreNextTextInput == false && string.IsNullOrEmpty(text) == false && TouchScreenKeyboard?.status == UnityEngine.TouchScreenKeyboard.Status.Done)
                {
                    //Need to clear the existing text in textbox before "pasting" new text from TouchScreenKeyboard
                    if (UIManager.KeyboardFocusControl is AbstractTextBox abstractTextBox)
                    {
                        abstractTextBox.EntryValue.Clear();
                    }

                    UIManager.KeyboardFocusControl?.InvokeTextInput(text);
                    _scene.OnTextInput(text);

                    //When targeting SystemChat textbox, "auto-press" return key so that the text entered on the TouchScreenKeyboard is submitted right away
                    if (UIManager.KeyboardFocusControl != null && UIManager.KeyboardFocusControl == UIManager.SystemChat?.TextBoxControl)
                    {
                        UIManager.KeyboardFocusControl.InvokeKeyDown(SDL_Keycode.SDLK_RETURN, SDL_Keymod.KMOD_NONE);
                    }

                    //Clear the text of TouchScreenKeyboard, otherwise it stays there and is re-evaluated every frame
                    TouchScreenKeyboard.text = string.Empty;
                }
            }
            else
            {
                var text = UnityEngine.Input.inputString;
                if (_ignoreNextTextInput == false && string.IsNullOrEmpty(text) == false)
                {
                    UIManager.KeyboardFocusControl?.InvokeTextInput(text);
                    _scene.OnTextInput(text);
                }
            }
        }
Beispiel #9
0
        private void UnityInputUpdate()
        {
            var oneOverScale = 1f / Batcher.scale;

            //Finger/mouse handling
            if (UnityEngine.Application.isMobilePlatform && UserPreferences.UseMouseOnMobile.CurrentValue == 0)
            {
                var fingers = Lean.Touch.LeanTouch.GetFingers(true, false);

                //Detect two finger tap gesture for closing gumps, only when one of the fingers' state is Down
                if (fingers.Count == 2 && (fingers[0].Down || fingers[1].Down))
                {
                    var firstMousePositionPoint  = ConvertUnityMousePosition(fingers[0].ScreenPosition, oneOverScale);
                    var secondMousePositionPoint = ConvertUnityMousePosition(fingers[1].ScreenPosition, oneOverScale);
                    var firstControlUnderFinger  = UIManager.GetMouseOverControl(firstMousePositionPoint);
                    var secondControlUnderFinger = UIManager.GetMouseOverControl(secondMousePositionPoint);
                    //We prefer to get the root parent but sometimes it can be null (like with GridLootGump), in which case we revert to the initially found control
                    firstControlUnderFinger  = firstControlUnderFinger?.RootParent ?? firstControlUnderFinger;
                    secondControlUnderFinger = secondControlUnderFinger?.RootParent ?? secondControlUnderFinger;
                    if (firstControlUnderFinger != null && firstControlUnderFinger == secondControlUnderFinger)
                    {
                        //Simulate right mouse down and up
                        SimulateMouse(false, false, true, false, false, true);
                        SimulateMouse(false, false, false, true, false, true);
                    }
                }
                //Only process one finger that has not started over gui because using multiple fingers with UIManager
                //causes issues due to the assumption that there's only one pointer, such as one finger "stealing" a
                //dragged gump from another
                else if (fingers.Count > 0)
                {
                    var finger      = fingers[0];
                    var mouseMotion = finger.ScreenPosition != finger.LastScreenPosition;
                    SimulateMouse(finger.Down, finger.Up, false, false, mouseMotion, false);
                }
            }
            else
            {
                var leftMouseDown  = UnityEngine.Input.GetMouseButtonDown(0);
                var leftMouseUp    = UnityEngine.Input.GetMouseButtonUp(0);
                var rightMouseDown = UnityEngine.Input.GetMouseButtonDown(1);
                var rightMouseUp   = UnityEngine.Input.GetMouseButtonUp(1);
                var mousePosition  = UnityEngine.Input.mousePosition;
                var mouseMotion    = mousePosition != lastMousePosition;
                lastMousePosition = mousePosition;

                if (Lean.Touch.LeanTouch.PointOverGui(mousePosition))
                {
                    Mouse.Position.X = 0;
                    Mouse.Position.Y = 0;
                    leftMouseDown    = false;
                    leftMouseUp      = false;
                    rightMouseDown   = false;
                    rightMouseUp     = false;
                }

                SimulateMouse(leftMouseDown, leftMouseUp, rightMouseDown, rightMouseUp, mouseMotion, false);
            }

            //Keyboard handling
            var keymod = KeymodOverride;

            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftAlt))
            {
                keymod |= SDL_Keymod.KMOD_LALT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.RightAlt))
            {
                keymod |= SDL_Keymod.KMOD_RALT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftShift))
            {
                keymod |= SDL_Keymod.KMOD_LSHIFT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.RightShift))
            {
                keymod |= SDL_Keymod.KMOD_RSHIFT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftControl))
            {
                keymod |= SDL_Keymod.KMOD_LCTRL;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.RightControl))
            {
                keymod |= SDL_Keymod.KMOD_RCTRL;
            }

            //Potential fix for hold alt to move gumps not working on mobile?
            Keyboard.Shift = (keymod & SDL_Keymod.KMOD_SHIFT) != SDL_Keymod.KMOD_NONE;
            Keyboard.Alt   = (keymod & SDL_Keymod.KMOD_ALT) != SDL_Keymod.KMOD_NONE;
            Keyboard.Ctrl  = (keymod & SDL_Keymod.KMOD_CTRL) != SDL_Keymod.KMOD_NONE;

            foreach (var keyCode in _keyCodeEnumValues)
            {
                var key = new SDL_KeyboardEvent {
                    keysym = new SDL_Keysym {
                        sym = (SDL_Keycode)keyCode, mod = keymod
                    }
                };
                if (UnityEngine.Input.GetKeyDown(keyCode))
                {
                    Keyboard.OnKeyDown(key);

                    if (Plugin.ProcessHotkeys((int)key.keysym.sym, (int)key.keysym.mod, true))
                    {
                        _ignoreNextTextInput = false;
                        UIManager.KeyboardFocusControl?.InvokeKeyDown(key.keysym.sym, key.keysym.mod);
                        _scene.OnKeyDown(key);
                    }
                    else
                    {
                        _ignoreNextTextInput = true;
                    }
                }
                if (UnityEngine.Input.GetKeyUp(keyCode))
                {
                    Keyboard.OnKeyUp(key);
                    UIManager.KeyboardFocusControl?.InvokeKeyUp(key.keysym.sym, key.keysym.mod);
                    _scene.OnKeyUp(key);
                    Plugin.ProcessHotkeys(0, 0, false);
                }
            }

            //Input text handling
            if (UnityEngine.Application.isMobilePlatform && TouchScreenKeyboard != null)
            {
                var text = TouchScreenKeyboard.text;

                if (_ignoreNextTextInput == false && TouchScreenKeyboard.status == UnityEngine.TouchScreenKeyboard.Status.Done)
                {
                    //Clear the text of TouchScreenKeyboard, otherwise it stays there and is re-evaluated every frame
                    TouchScreenKeyboard.text = string.Empty;

                    //Set keyboard to null so we process its text only once when its status is set to Done
                    TouchScreenKeyboard = null;

                    //Need to clear the existing text in textbox before "pasting" new text from TouchScreenKeyboard
                    if (UIManager.KeyboardFocusControl is StbTextBox stbTextBox)
                    {
                        stbTextBox.SetText(string.Empty);
                    }

                    UIManager.KeyboardFocusControl?.InvokeTextInput(text);
                    _scene.OnTextInput(text);

                    //When targeting SystemChat textbox, "auto-press" return key so that the text entered on the TouchScreenKeyboard is submitted right away
                    if (UIManager.KeyboardFocusControl != null && UIManager.KeyboardFocusControl == UIManager.SystemChat?.TextBoxControl)
                    {
                        //Handle different chat modes
                        HandleChatMode(text);
                        //"Press" return
                        UIManager.KeyboardFocusControl.InvokeKeyDown(SDL_Keycode.SDLK_RETURN, SDL_Keymod.KMOD_NONE);
                        //Revert chat mode to default
                        UIManager.SystemChat.Mode = ChatMode.Default;
                    }
                }
            }
            else
            {
                var text = UnityEngine.Input.inputString;
                //Backspace character should not be sent as text input
                text = text.Replace("\b", "");
                if (_ignoreNextTextInput == false && string.IsNullOrEmpty(text) == false)
                {
                    UIManager.KeyboardFocusControl?.InvokeTextInput(text);
                    _scene.OnTextInput(text);
                }
            }
        }
        private void UnityInputUpdate()
        {
            //Mouse handling
            var oneOverScale = 1f / scale;

            Mouse.Position.X   = UnityEngine.Mathf.RoundToInt(UnityEngine.Input.mousePosition.x * oneOverScale);
            Mouse.Position.Y   = UnityEngine.Mathf.RoundToInt((UnityEngine.Screen.height - UnityEngine.Input.mousePosition.y) * oneOverScale);
            Mouse.RealPosition = Mouse.Position;

            var leftMouseDown = UnityEngine.Input.GetMouseButtonDown(0);
            var leftMouseHeld = UnityEngine.Input.GetMouseButton(0);
            var leftMouseUp   = UnityEngine.Input.GetMouseButtonUp(0);

            var rightMouseDown = UnityEngine.Input.GetMouseButtonDown(1);
            var rightMouseHeld = UnityEngine.Input.GetMouseButton(1);
            var rightMouseUp   = UnityEngine.Input.GetMouseButtonUp(1);

            if (MouseOverGui)
            {
                Mouse.Position.X = 0;
                Mouse.Position.Y = 0;
                leftMouseDown    = false;
                leftMouseHeld    = false;
                leftMouseUp      = false;
                rightMouseDown   = false;
                rightMouseHeld   = false;
                rightMouseUp     = false;
            }

            Mouse.LButtonPressed = leftMouseDown || leftMouseHeld;
            Mouse.RButtonPressed = rightMouseDown || rightMouseHeld;
            Mouse.MButtonPressed = UnityEngine.Input.GetMouseButtonDown(2) || UnityEngine.Input.GetMouseButton(2);

            Mouse.IsDragging   = Mouse.LButtonPressed || Mouse.RButtonPressed || Mouse.MButtonPressed;
            Mouse.RealPosition = Mouse.Position;

            //Added additional check for mouseWasDown because otherwise, on mobile, tapping somewhere would immediately
            //set mouseMotion to true since the previous tap position was almost guaranteed to be at another position
            //due to input inaccuracy. We do not want a new tap to be recognized as a mouseMotion.
            var mouseMotion = UnityEngine.Input.mousePosition != lastMousePosition && mouseWasDown;

            lastMousePosition = UnityEngine.Input.mousePosition;

            if (_dragStarted && !Mouse.LButtonPressed)
            {
                _dragStarted = false;
            }

            if (leftMouseDown)
            {
                mouseWasDown = true;
                Mouse.Begin();
                Mouse.LDropPosition     = Mouse.Position;
                Mouse.CancelDoubleClick = false;
                uint ticks = Time.Ticks;
                if (Mouse.LastLeftButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks)
                {
                    Mouse.LastLeftButtonClickTime = 0;

                    bool res = UIManager.ValidForDClick() ? UIManager.OnLeftMouseDoubleClick() : _scene.OnLeftMouseDoubleClick();

                    if (!res)
                    {
                        _scene.OnLeftMouseDown();
                        UIManager.OnLeftMouseButtonDown();
                    }
                    else
                    {
                        Mouse.LastLeftButtonClickTime = 0xFFFF_FFFF;
                    }
                }
                else
                {
                    _scene.OnLeftMouseDown();
                    UIManager.OnLeftMouseButtonDown();
                    Mouse.LastLeftButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks;
                }
            }
            else if (leftMouseUp)
            {
                mouseWasDown = false;
                if (Mouse.LastLeftButtonClickTime != 0xFFFF_FFFF)
                {
                    if (!UIManager.HadMouseDownOnGump(MouseButtonType.Left))
                    {
                        _scene.OnLeftMouseUp();
                    }
                    UIManager.OnLeftMouseButtonUp();
                }
                Mouse.End();
            }

            if (rightMouseDown)
            {
                Mouse.Begin();
                Mouse.RDropPosition     = Mouse.Position;
                Mouse.CancelDoubleClick = false;
                uint ticks = Time.Ticks;

                if (Mouse.LastRightButtonClickTime + Mouse.MOUSE_DELAY_DOUBLE_CLICK >= ticks)
                {
                    Mouse.LastRightButtonClickTime = 0;

                    bool res = _scene.OnRightMouseDoubleClick() || UIManager.OnRightMouseDoubleClick();

                    if (!res)
                    {
                        _scene.OnRightMouseDown();
                        UIManager.OnRightMouseButtonDown();
                    }
                    else
                    {
                        Mouse.LastRightButtonClickTime = 0xFFFF_FFFF;
                    }
                }
                else
                {
                    _scene.OnRightMouseDown();
                    UIManager.OnRightMouseButtonDown();
                    Mouse.LastRightButtonClickTime = Mouse.CancelDoubleClick ? 0 : ticks;
                }
            }
            else if (rightMouseUp)
            {
                if (Mouse.LastRightButtonClickTime != 0xFFFF_FFFF)
                {
                    if (!UIManager.HadMouseDownOnGump(MouseButtonType.Right))
                    {
                        _scene.OnRightMouseUp();
                    }
                    UIManager.OnRightMouseButtonUp();
                }
                Mouse.End();
            }

            if (mouseMotion)
            {
                if (Mouse.IsDragging)
                {
                    UIManager.OnMouseDragging();
                    _scene.OnMouseDragging();
                }

                if (Mouse.IsDragging && !_dragStarted)
                {
                    _dragStarted = true;
                }
            }

            //Keyboard handling

            var keymod = SDL.SDL_Keymod.KMOD_NONE;

            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftAlt))
            {
                keymod |= SDL_Keymod.KMOD_LALT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.RightAlt))
            {
                keymod |= SDL_Keymod.KMOD_RALT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftShift))
            {
                keymod |= SDL_Keymod.KMOD_LSHIFT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.RightShift))
            {
                keymod |= SDL_Keymod.KMOD_RSHIFT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftControl))
            {
                keymod |= SDL_Keymod.KMOD_LCTRL;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.RightControl))
            {
                keymod |= SDL_Keymod.KMOD_RCTRL;
            }
            foreach (var keyCode in _keyCodeEnumValues)
            {
                if (UnityEngine.Input.GetKeyDown(keyCode))
                {
                    var key = new SDL_KeyboardEvent()
                    {
                        keysym = new SDL_Keysym()
                        {
                            sym = (SDL_Keycode)keyCode, mod = keymod
                        }
                    };
                    Keyboard.OnKeyDown(key);

                    if (Plugin.ProcessHotkeys((int)key.keysym.sym, (int)key.keysym.mod, true))
                    {
                        _ignoreNextTextInput = false;

                        //UIManager.MouseOverControl?.InvokeKeyDown(e.key.keysym.sym, e.key.keysym.mod);
                        //if (UIManager.MouseOverControl != UIManager.KeyboardFocusControl)
                        UIManager.KeyboardFocusControl?.InvokeKeyDown(key.keysym.sym, key.keysym.mod);

                        _scene.OnKeyDown(key);
                    }
                    else
                    {
                        _ignoreNextTextInput = true;
                    }
                }
                if (UnityEngine.Input.GetKeyUp(keyCode))
                {
                    var key = new SDL_KeyboardEvent()
                    {
                        keysym = new SDL_Keysym()
                        {
                            sym = (SDL_Keycode)keyCode
                        }
                    };
                    Keyboard.OnKeyUp(key);
                    UIManager.KeyboardFocusControl?.InvokeKeyUp(key.keysym.sym, key.keysym.mod);
                    _scene.OnKeyUp(key);
                }
            }

            //Input text handling
            if (UnityEngine.Application.isMobilePlatform)
            {
                var text = TouchScreenKeyboard?.text;
                if (_ignoreNextTextInput == false && string.IsNullOrEmpty(text) == false && TouchScreenKeyboard?.status == UnityEngine.TouchScreenKeyboard.Status.Done)
                {
                    //Need to clear the existing text in textbox before "pasting" new text from TouchScreenKeyboard
                    if (UIManager.KeyboardFocusControl is AbstractTextBox abstractTextBox)
                    {
                        abstractTextBox.EntryValue.Clear();
                    }

                    UIManager.KeyboardFocusControl?.InvokeTextInput(text);
                    _scene.OnTextInput(text);

                    //When targeting SystemChat textbox, "auto-press" return key so that the text entered on the TouchScreenKeyboard is submitted right away
                    if (UIManager.KeyboardFocusControl != null && UIManager.KeyboardFocusControl == UIManager.SystemChat?.TextBoxControl)
                    {
                        UIManager.KeyboardFocusControl.InvokeKeyDown(SDL_Keycode.SDLK_RETURN, SDL_Keymod.KMOD_NONE);
                    }

                    //Clear the text of TouchScreenKeyboard, otherwise it stays there and is re-evaluated every frame
                    TouchScreenKeyboard.text = string.Empty;
                }
            }
            else
            {
                var text = UnityEngine.Input.inputString;
                if (_ignoreNextTextInput == false && string.IsNullOrEmpty(text) == false)
                {
                    UIManager.KeyboardFocusControl?.InvokeTextInput(text);
                    _scene.OnTextInput(text);
                }
            }
        }
Beispiel #11
0
        private void UnityInputUpdate()
        {
            var oneOverScale = 1f / Batcher.scale;

            //Finger/mouse handling
            if (UnityEngine.Application.isMobilePlatform && UserPreferences.UseMouseOnMobile.CurrentValue == 0)
            {
                var fingers = Lean.Touch.LeanTouch.GetFingers(true, false);

                //Detect two finger tap gesture for closing gumps
                for (int i = 0; i < fingers.Count && i < 5; i++)
                {
                    var finger = fingers[i];
                    if (finger.Age < 0.1f)
                    {
                        var mousePositionPoint = ConvertUnityMousePosition(finger.ScreenPosition, oneOverScale);
                        controlsUnderFingers[i] = UIManager.GetMouseOverControl(mousePositionPoint)?.RootParent;
                        if (controlsUnderFingers[i] != null)
                        {
                            for (int k = 0; k < i; k++)
                            {
                                if (controlsUnderFingers[k] == controlsUnderFingers[i])
                                {
                                    //Simulate right mouse down and up
                                    SimulateMouse(false, false, true, false, false, true);
                                    SimulateMouse(false, false, false, true, false, true);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        controlsUnderFingers[i] = null;
                    }
                }

                //Only process one finger that has not started over gui because using multiple fingers with UIManager
                //causes issues due to the assumption that there's only one pointer, such as on finger "stealing"
                //a dragged gump from another
                if (fingers.Count > 0)
                {
                    var finger      = fingers[0];
                    var mouseMotion = finger.ScreenPosition != finger.LastScreenPosition;
                    SimulateMouse(finger.Down, finger.Up, false, false, mouseMotion, false);
                }
            }
            else
            {
                var leftMouseDown  = UnityEngine.Input.GetMouseButtonDown(0);
                var leftMouseUp    = UnityEngine.Input.GetMouseButtonUp(0);
                var rightMouseDown = UnityEngine.Input.GetMouseButtonDown(1);
                var rightMouseUp   = UnityEngine.Input.GetMouseButtonUp(1);
                var mousePosition  = UnityEngine.Input.mousePosition;
                var mouseMotion    = mousePosition != lastMousePosition;
                lastMousePosition = mousePosition;

                if (Lean.Touch.LeanTouch.PointOverGui(mousePosition))
                {
                    Mouse.Position.X = 0;
                    Mouse.Position.Y = 0;
                    leftMouseDown    = false;
                    leftMouseUp      = false;
                    rightMouseDown   = false;
                    rightMouseUp     = false;
                }

                SimulateMouse(leftMouseDown, leftMouseUp, rightMouseDown, rightMouseUp, mouseMotion, false);
            }

            //Keyboard handling
            var keymod = SDL.SDL_Keymod.KMOD_NONE;

            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftAlt))
            {
                keymod |= SDL_Keymod.KMOD_LALT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.RightAlt))
            {
                keymod |= SDL_Keymod.KMOD_RALT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftShift))
            {
                keymod |= SDL_Keymod.KMOD_LSHIFT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.RightShift))
            {
                keymod |= SDL_Keymod.KMOD_RSHIFT;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.LeftControl))
            {
                keymod |= SDL_Keymod.KMOD_LCTRL;
            }
            if (UnityEngine.Input.GetKey(UnityEngine.KeyCode.RightControl))
            {
                keymod |= SDL_Keymod.KMOD_RCTRL;
            }
            foreach (var keyCode in _keyCodeEnumValues)
            {
                var key = new SDL_KeyboardEvent {
                    keysym = new SDL_Keysym {
                        sym = (SDL_Keycode)keyCode, mod = keymod
                    }
                };
                if (UnityEngine.Input.GetKeyDown(keyCode))
                {
                    Keyboard.OnKeyDown(key);
                    UIManager.KeyboardFocusControl?.InvokeKeyDown(key.keysym.sym, key.keysym.mod);
                    _scene.OnKeyDown(key);
                }
                if (UnityEngine.Input.GetKeyUp(keyCode))
                {
                    Keyboard.OnKeyUp(key);
                    UIManager.KeyboardFocusControl?.InvokeKeyUp(key.keysym.sym, key.keysym.mod);
                    _scene.OnKeyUp(key);
                }
            }

            //Input text handling
            if (UnityEngine.Application.isMobilePlatform)
            {
                var text = TouchScreenKeyboard?.text;
                if (_ignoreNextTextInput == false && TouchScreenKeyboard?.status == UnityEngine.TouchScreenKeyboard.Status.Done)
                {
                    //Set keyboard to null so we process its text only once when its status is set to Done
                    TouchScreenKeyboard = null;
                    //Need to clear the existing text in textbox before "pasting" new text from TouchScreenKeyboard
                    if (UIManager.KeyboardFocusControl is StbTextBox stbTextBox)
                    {
                        stbTextBox.SetText(string.Empty);
                    }

                    UIManager.KeyboardFocusControl?.InvokeTextInput(text);
                    _scene.OnTextInput(text);

                    //When targeting SystemChat textbox, "auto-press" return key so that the text entered on the TouchScreenKeyboard is submitted right away
                    if (UIManager.KeyboardFocusControl != null && UIManager.KeyboardFocusControl == UIManager.SystemChat?.TextBoxControl)
                    {
                        UIManager.KeyboardFocusControl.InvokeKeyDown(SDL_Keycode.SDLK_RETURN, SDL_Keymod.KMOD_NONE);
                    }

                    //Clear the text of TouchScreenKeyboard, otherwise it stays there and is re-evaluated every frame
                    TouchScreenKeyboard.text = string.Empty;
                }
            }
            else
            {
                var text = UnityEngine.Input.inputString;
                //Backspace character should not be sent as text input
                text = text.Replace("\b", "");
                if (_ignoreNextTextInput == false && string.IsNullOrEmpty(text) == false)
                {
                    UIManager.KeyboardFocusControl?.InvokeTextInput(text);
                    _scene.OnTextInput(text);
                }
            }
        }
Beispiel #12
0
 private void onKeyReleased(SDL_KeyboardEvent args)
 {
     this.currentState[args.keysym.scancode] = false;
     this.releasedKeys.Add(args.keysym.sym);
 }
Beispiel #13
0
 private void OnKeyEvent(SDL_KeyboardEvent keyEvent, bool pressed)
     => OnKeyEvent(keyEvent.keysym.sym, pressed, keyEvent.repeat != 0);
Beispiel #14
0
 public SdlKeyboardEvent(SDL_KeyboardEvent handle)
 {
     _handle = handle;
 }
Beispiel #15
0
        /// <summary>
        /// 直接转换相关事件
        /// </summary>
        /// <param name="ev"></param>
        public static unsafe void HandleEvent(SDL_Event *ev)
        {
            if (_host == null)
            {
                return;
            }
            switch (ev->type)
            {
            case SDL_EventType.Quit:
                //Close();
                break;

            case SDL_EventType.Terminating:
                //Close();
                break;

            case SDL_EventType.WindowEvent:
                //SDL_WindowEvent windowEvent = Unsafe.Read<SDL_WindowEvent>(ev);
                //HandleWindowEvent(windowEvent);
                break;

            case SDL_EventType.KeyDown:
            case SDL_EventType.KeyUp:
                SDL_KeyboardEvent keyboardEvent = Unsafe.Read <SDL_KeyboardEvent>(ev);
                HandleKeyboardEvent(keyboardEvent);
                break;

            case SDL_EventType.TextEditing:
                break;

            case SDL_EventType.TextInput:
                SDL_TextInputEvent textInputEvent = Unsafe.Read <SDL_TextInputEvent>(ev);
                HandleTextInputEvent(textInputEvent);
                break;

            case SDL_EventType.KeyMapChanged:
                break;

            case SDL_EventType.MouseMotion:
                SDL_MouseMotionEvent mouseMotionEvent = Unsafe.Read <SDL_MouseMotionEvent>(ev);
                HandleMouseMotionEvent(mouseMotionEvent);
                break;

            case SDL_EventType.MouseButtonDown:
            case SDL_EventType.MouseButtonUp:
                SDL_MouseButtonEvent mouseButtonEvent = Unsafe.Read <SDL_MouseButtonEvent>(ev);
                HandleMouseButtonEvent(mouseButtonEvent);
                break;

            case SDL_EventType.MouseWheel:
                SDL_MouseWheelEvent mouseWheelEvent = Unsafe.Read <SDL_MouseWheelEvent>(ev);
                HandleMouseWheelEvent(mouseWheelEvent);
                break;

            case SDL_EventType.JoyAxisMotion:
                break;

            case SDL_EventType.JoyBallMotion:
                break;

            case SDL_EventType.JoyHatMotion:
                break;

            case SDL_EventType.JoyButtonDown:
                break;

            case SDL_EventType.JoyButtonUp:
                break;

            case SDL_EventType.JoyDeviceAdded:
                break;

            case SDL_EventType.JoyDeviceRemoved:
                break;

            case SDL_EventType.ControllerAxisMotion:
                break;

            case SDL_EventType.ControllerButtonDown:
                break;

            case SDL_EventType.ControllerButtonUp:
                break;

            case SDL_EventType.ControllerDeviceAdded:
                break;

            case SDL_EventType.ControllerDeviceRemoved:
                break;

            case SDL_EventType.ControllerDeviceRemapped:
                break;

            case SDL_EventType.FingerDown:
                break;

            case SDL_EventType.FingerUp:
                break;

            case SDL_EventType.FingerMotion:
                break;

            case SDL_EventType.DollarGesture:
                break;

            case SDL_EventType.DollarRecord:
                break;

            case SDL_EventType.MultiGesture:
                break;

            case SDL_EventType.ClipboardUpdate:
                break;

            case SDL_EventType.DropFile:
                break;

            case SDL_EventType.DropTest:
                break;

            case SDL_EventType.DropBegin:
                break;

            case SDL_EventType.DropComplete:
                break;

            case SDL_EventType.AudioDeviceAdded:
                break;

            case SDL_EventType.AudioDeviceRemoved:
                break;

            case SDL_EventType.RenderTargetsReset:
                break;

            case SDL_EventType.RenderDeviceReset:
                break;

            case SDL_EventType.UserEvent:
                break;

            case SDL_EventType.LastEvent:
                break;

            default:
                // Ignore
                break;
            }
        }