private void OnPreviewPaste(object sender, DataObjectPastingEventArgs e)
 {
     if (InputModifier != null)
     {
         InputModifier.AcceptPaste(e);
     }
 }
 protected override void OnPreviewKeyDown(KeyEventArgs e)
 {
     if (e.Key == Key.Escape)
     {
         Text = textBackup;
         UpdateSource();
         Keyboard.ClearFocus();
     }
     else if (e.Key == Key.Enter || e.Key == Key.Tab)
     {
         if (e.Key == Key.Enter)
         {
             Keyboard.ClearFocus();
         }
         if (String.IsNullOrWhiteSpace(Text))
         {
             Text = "0";
         }
         UpdateSource();
     }
     else if (InputModifier != null)
     {
         KeyEventArgs modifiedEventArgs = InputModifier.AcceptKeyDown(e);
         if (modifiedEventArgs != null)
         {
             base.OnPreviewKeyDown(modifiedEventArgs);
         }
     }
     base.OnPreviewKeyDown(e);
     if ((e.Key == Key.Back || e.Key == Key.Delete) && ImmediateTargetRefresh)
     {
         TextChanged += ModifiedInputTextBox_TextChanged;
     }
 }
예제 #3
0
 private void DoMyThing()
 {
     if (inputModifier.scale.sqrMagnitude < Mathf.Epsilon)
     {
         inputModifier = InputModifier.DefaultIM();
     }
     AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(shader));
     InitComputeShader();
     RunKernel();
 }
예제 #4
0
        private CefEventFlags DecodeInputModifier(InputModifier modifier)
        {
            var result = CefEventFlags.None;

            if ((modifier & InputModifier.Shift) == InputModifier.Shift)
            {
                result |= CefEventFlags.ShiftDown;
            }
            if ((modifier & InputModifier.Control) == InputModifier.Control)
            {
                result |= CefEventFlags.ControlDown;
            }
            if ((modifier & InputModifier.Alt) == InputModifier.Alt)
            {
                result |= CefEventFlags.AltDown;
            }
            return(result);
        }
예제 #5
0
        public static bool WasLastInputFromController => false;         // !NativeWrappers.IsInputDisabled(2); TODO

        public static bool IsControlModifierPressed(InputModifier modifier)
        {
            if (modifier == InputModifier.Any)
            {
                return(true);
            }

            InputModifier bitMask = 0;

            ModifierFlagToKeyCode.ToList().ForEach(w =>
            {
                if (Game.IsControlPressed(0, (Control)w.Value))
                {
                    bitMask = bitMask | w.Key;
                }
            });

            return(bitMask == modifier);
        }
 protected override void OnPreviewTextInput(TextCompositionEventArgs e)
 {
     if (InputModifier != null)
     {
         TextCompositionEventArgs modifiedEventArgs = InputModifier.AcceptText(e);
         if (modifiedEventArgs != null)
         {
             base.OnPreviewTextInput(modifiedEventArgs);
         }
     }
     else
     {
         base.OnPreviewTextInput(e);
     }
     if (ImmediateTargetRefresh)
     {
         TextChanged += ModifiedInputTextBox_TextChanged;
     }
 }
예제 #7
0
 public static bool IsEnabledControlPressed(Control control, bool keyboardOnly = true, InputModifier modifier = InputModifier.None)
 {
     return(Game.IsEnabledControlPressed(0, control) && (!keyboardOnly || !WasLastInputFromController) && IsControlModifierPressed(modifier));
 }
예제 #8
0
 private void Awake()
 {
     inputModifier = GetComponent <InputModifier>();
     pageManager   = GetComponent <PageManager>();
 }
예제 #9
0
        public (bool, long) WndProcMessage(WindowsMessage msg, ulong wParam, long lParam)
        {
            // Check if there was a click, and use it to set the window focused state
            // We're avoiding ImGui for this, as we want to check for clicks entirely outside
            // ImGui's pervue to defocus inlays
            if (msg == WindowsMessage.WM_LBUTTONDOWN)
            {
                windowFocused = mouseInWindow && captureCursor;
            }

            // Bail if we're not focused
            // TODO: Revisit this for UI stuff, might not hold
            if (!windowFocused)
            {
                return(false, 0);
            }

            KeyEventType?eventType = msg switch
            {
                WindowsMessage.WM_KEYDOWN => KeyEventType.KeyDown,
                WindowsMessage.WM_SYSKEYDOWN => KeyEventType.KeyDown,
                WindowsMessage.WM_KEYUP => KeyEventType.KeyUp,
                WindowsMessage.WM_SYSKEYUP => KeyEventType.KeyUp,
                WindowsMessage.WM_CHAR => KeyEventType.Character,
                WindowsMessage.WM_SYSCHAR => KeyEventType.Character,
                _ => (KeyEventType?)null,
            };

            // If the event isn't something we're tracking, bail early with no capture
            if (eventType == null)
            {
                return(false, 0);
            }

            var isSystemKey = false ||
                              msg == WindowsMessage.WM_SYSKEYDOWN ||
                              msg == WindowsMessage.WM_SYSKEYUP ||
                              msg == WindowsMessage.WM_SYSCHAR;

            // TODO: Technically this is only firing once, because we're checking focused before this point,
            // but having this logic essentially duped per-inlay is a bit eh. Dedupe at higher point?
            var modifierAdjust = InputModifier.None;

            if (wParam == (int)VirtualKey.Shift)
            {
                modifierAdjust |= InputModifier.Shift;
            }
            if (wParam == (int)VirtualKey.Control)
            {
                modifierAdjust |= InputModifier.Control;
            }
            // SYS* messages signal alt is held (really?)
            if (isSystemKey)
            {
                modifierAdjust |= InputModifier.Alt;
            }

            if (eventType == KeyEventType.KeyDown)
            {
                modifier |= modifierAdjust;
            }
            else if (eventType == KeyEventType.KeyUp)
            {
                modifier &= ~modifierAdjust;
            }

            renderProcess.Send(new KeyEventRequest()
            {
                Guid          = RenderGuid,
                Type          = eventType.Value,
                SystemKey     = isSystemKey,
                UserKeyCode   = (int)wParam,
                NativeKeyCode = (int)lParam,
                Modifier      = modifier,
            });

            // We've handled the input, signal. For these message types, `0` signals a capture.
            return(true, 0);
        }
예제 #10
0
        private void HandleMouseEvent()
        {
            // Render proc won't be ready on first boot
            // Totally skip mouse handling for click through inlays, as well
            if (renderProcess == null || inlayConfig.ClickThrough)
            {
                return;
            }

            var io        = ImGui.GetIO();
            var windowPos = ImGui.GetWindowPos();
            var mousePos  = io.MousePos - windowPos - ImGui.GetWindowContentRegionMin();

            // Generally we want to use IsWindowHovered for hit checking, as it takes z-stacking into account -
            // but when cursor isn't being actively captured, imgui will always return false - so fall back
            // so a slightly more naive hover check, just to maintain a bit of flood prevention.
            // TODO: Need to test how this will handle overlaps... fully transparent _shouldn't_ be accepting
            //       clicks so shouuulllddd beee fineee???
            var hovered = captureCursor
                                ? ImGui.IsWindowHovered()
                                : ImGui.IsMouseHoveringRect(windowPos, windowPos + ImGui.GetWindowSize());

            // If the cursor is outside the window, send a final mouse leave then noop
            if (!hovered)
            {
                if (mouseInWindow)
                {
                    mouseInWindow = false;
                    renderProcess.Send(new MouseEventRequest()
                    {
                        Guid    = RenderGuid,
                        X       = mousePos.X,
                        Y       = mousePos.Y,
                        Leaving = true,
                    });
                }
                return;
            }
            mouseInWindow = true;

            ImGui.SetMouseCursor(cursor);

            var down    = EncodeMouseButtons(io.MouseClicked);
            var double_ = EncodeMouseButtons(io.MouseDoubleClicked);
            var up      = EncodeMouseButtons(io.MouseReleased);
            var wheelX  = io.MouseWheelH;
            var wheelY  = io.MouseWheel;

            // If the event boils down to no change, bail before sending
            if (io.MouseDelta == Vector2.Zero && down == MouseButton.None && double_ == MouseButton.None && up == MouseButton.None && wheelX == 0 && wheelY == 0)
            {
                return;
            }

            var modifier = InputModifier.None;

            if (io.KeyShift)
            {
                modifier |= InputModifier.Shift;
            }
            if (io.KeyCtrl)
            {
                modifier |= InputModifier.Control;
            }
            if (io.KeyAlt)
            {
                modifier |= InputModifier.Alt;
            }

            // TODO: Either this or the entire handler function should be asynchronous so we're not blocking the entire draw thread
            renderProcess.Send(new MouseEventRequest()
            {
                Guid     = RenderGuid,
                X        = mousePos.X,
                Y        = mousePos.Y,
                Down     = down,
                Double   = double_,
                Up       = up,
                WheelX   = wheelX,
                WheelY   = wheelY,
                Modifier = modifier,
            });
        }