Beispiel #1
0
 private void ProcessModifierKeys(RawInputEventArgs args)
 {
     if (args is RawKeyEventArgs keyArgs)
     {
         currentModifiers = keyArgs.Modifiers;
     }
 }
Beispiel #2
0
        void RawDevice_RawInput(object sender, RawInputEventArgs e)
        {
            if (e.Handle != IntPtr.Zero)
            {
                MouseData  data       = (MouseData)e.GetRawData();
                CursorData cursorData = deviceList[e.Handle];

                MouseButtonState oldState = cursorData.ButtonState;
                MouseButtonState newState = data.ButtonState;

                double x = cursorData.X + data.X;
                double y = cursorData.Y + data.Y;

                if (newState == MouseButtonState.LeftDown)
                {
                    OnMouseDown(e.Handle, x, y, cursorData.X, cursorData.Y);
                }
                else if (newState == MouseButtonState.LeftUp)
                {
                    OnMouseUp(e.Handle, x, y, cursorData.X, cursorData.Y);
                }
                else if (oldState == MouseButtonState.LeftDown)
                {
                    OnMouseMove(e.Handle, x, y, cursorData.X, cursorData.Y);
                }

                if (newState != MouseButtonState.None)
                {
                    cursorData.ButtonState = newState;
                }
                dispatcher.Invoke(DispatcherPriority.Normal, (Action) delegate { cursorData.SetPosition(x, y); });
            }
        }
        void HandleInput(RawInputEventArgs args)
        {
            if (args is RawKeyEventArgs rawKeyEventArgs)
            {
                // cmd + back = delete
                if (rawKeyEventArgs.Modifiers.HasFlag(RawInputModifiers.Meta) && rawKeyEventArgs.Key == Key.Back)
                {
                    rawKeyEventArgs.Modifiers = RawInputModifiers.None;
                    rawKeyEventArgs.Key       = Key.Delete;
                }

                // swap cmd and ctrl
                var modifier = rawKeyEventArgs.Modifiers & ~RawInputModifiers.Control & ~RawInputModifiers.Meta;
                if (rawKeyEventArgs.Modifiers.HasFlag(RawInputModifiers.Meta))
                {
                    modifier |= RawInputModifiers.Control;
                }
                if (rawKeyEventArgs.Modifiers.HasFlag(RawInputModifiers.Control))
                {
                    modifier |= RawInputModifiers.Meta;
                }

                rawKeyEventArgs.Modifiers = modifier;
            }

            originalInputEventHanlder(args);
        }
        public bool PreprocessInputEvent(ref RawInputEventArgs e)
        {
            if (_edge == null)
            {
                return(false);
            }
            if (e is RawMouseEventArgs args)
            {
                if (args.Type == RawMouseEventType.LeftButtonUp)
                {
                    _edge = null;
                    _captureMouse(false);
                }
                if (args.Type == RawMouseEventType.Move)
                {
                    MoveWindow(args.Position);
                    return(true);
                }


                _edge = null;
            }

            return(false);
        }
Beispiel #5
0
 private void RawInput_ButtonUp(object sender, RawInputEventArgs e)
 {
     if (e.Button == App.Settings.Current.Voice.TalkKey)
     {
         _isTalkKeyDown = false;
     }
 }
Beispiel #6
0
        private static void RawInputOnKeyPressed(object sender, RawInputEventArgs e)
        {
            if (e.KeyPressState == KeyPressState.Up && _watchKeys.ContainsKey(e.Key))
            {
                _watchKeys[e.Key]?.Invoke();
            }

            if (IsWaitingForScanner)
            {
                Config.Rfid.ScannerId   = GetScannerId(e.Device);
                Config.Rfid.Description = e.Device.Description;
                Config.Rfid.ScannerType = e.Device.Type.ToString();
                Config.Rfid.Fullname    = e.Device.Name;
                Config.Rfid.Handle      = e.Device.Handle.ToInt64();
                Config.Rfid.Save();
                IsWaitingForScanner = false;
                Messenger.Default.Broadcast(Messages.ScannerRegistered);
                _input.Clear();
                e.Handled = true;
                return;
            }

            if (Config.Rfid.Fullname == e.Device.Name)
            {
                Config.Rfid.Handle = e.Device.Handle.ToInt64();

                if (e.KeyPressState != KeyPressState.Down)
                {
                    return;
                }
                if (e.Key != Key.Enter)
                {
                    _input.Append((char)e.VirtualKey);
                }
                else
                {
                    if (_input.Length == 0)
                    {
                        return;
                    }
                    e.Handled = true;

                    if (ExclusiveCallback != null)
                    {
                        ExclusiveCallback(_input.ToString());
                    }
                    else
                    {
                        Messenger.Default.Broadcast(Messages.Scan, _input.ToString());
                    }

                    _input.Clear();
                }

                if (Config.Rfid.UseExclusive || RfidScanner.ExclusiveCallback != null)
                {
                    e.Handled = true;
                }
            }
        }
Beispiel #7
0
 private void ScheduleInput(RawInputEventArgs ev)
 {
     lock (_inputQueue)
     {
         _inputQueue.Enqueue(ev);
         if (_inputQueue.Count == 1)
         {
             Dispatcher.UIThread.Post(() =>
             {
                 while (true)
                 {
                     Dispatcher.UIThread.RunJobs(DispatcherPriority.Input + 1);
                     RawInputEventArgs dequeuedEvent = null;
                     lock (_inputQueue)
                         if (_inputQueue.Count != 0)
                         {
                             dequeuedEvent = _inputQueue.Dequeue();
                         }
                     if (dequeuedEvent == null)
                     {
                         return;
                     }
                     _onInput?.Invoke(dequeuedEvent);
                 }
             }, DispatcherPriority.Input);
         }
     }
 }
Beispiel #8
0
 /// <inheritdoc/>
 public void ProcessInput(RawInputEventArgs e)
 {
     _preProcess.OnNext(e);
     e.Device?.ProcessRawEvent(e);
     _process.OnNext(e);
     _postProcess.OnNext(e);
 }
Beispiel #9
0
 private void OnKeyPressed(object sender, RawInputEventArgs e)
 {
     if (e.KeyPressEvent.IsKeyDown && e.KeyPressEvent.DeviceName == ActiveDeviceName)
     {
         view.AppendText(e.KeyPressEvent.VKeyName);
     }
 }
        private void OnRawInput(object sender, RawInputEventArgs e)
        {
            var handler = ButtonsChanged;

            if (handler == null)
            {
                return;
            }

            var hidInput = e as HidInputEventArgs;

            if (hidInput == null)
            {
                return;
            }

            if (e.Device == IntPtr.Zero)
            {
                return;
            }

            var           deviceName = DeviceHelper.SearchDevice(e.Device).DeviceName;
            List <ushort> pressedButtons;

            RawInputParser.Parse(hidInput, out pressedButtons);

            handler(this, new GamepadEventArgs(pressedButtons, deviceName));
        }
Beispiel #11
0
        /// <summary>
        /// Captures mouse input to the specified control.
        /// </summary>
        /// <param name="control">The control.</param>
        /// <remarks>
        /// When an element captures the mouse, it receives mouse input whether the cursor is
        /// within the control's bounds or not. The current mouse capture control is exposed
        /// by the <see cref="Captured"/> property.
        /// </remarks>
        //public virtual void Capture(IInputElement control)
        //{
        //    // TODO: Check visibility and enabled state before setting capture.
        //    Captured = control;
        //}

        /// <summary>
        /// Gets the mouse position relative to a control.
        /// </summary>
        /// <param name="relativeTo">The control.</param>
        /// <returns>The mouse position in the control's coordinates.</returns>
        //public Point GetPosition(IVisual relativeTo)
        //{
        //    Contract.Requires<ArgumentNullException>(relativeTo != null);

        //    if (relativeTo.VisualRoot == null)
        //    {
        //        throw new InvalidOperationException("Control is not attached to visual tree.");
        //    }

        //    var rootPoint = relativeTo.VisualRoot.PointToClient(Position);
        //    var transform = relativeTo.VisualRoot.TransformToVisual(relativeTo);
        //    return rootPoint * transform.Value;
        //}

        public void ProcessRawEvent(RawInputEventArgs e)
        {
            if (!e.Handled && e is RawMouseEventArgs margs)
            {
                ProcessRawEvent(margs);
            }
        }
Beispiel #12
0
 private void OnRawEvent(RawInputEventArgs obj)
 {
     lock (_lock)
     {
         _inputQueue.Enqueue(obj);
         TriggerQueueHandler();
     }
 }
Beispiel #13
0
        public void ProcessRawEvent(RawInputEventArgs ev)
        {
            var args = (RawTouchEventArgs)ev;

            if (!_pointers.TryGetValue(args.TouchPointId, out var pointer))
            {
                if (args.Type == RawPointerEventType.TouchEnd)
                {
                    return;
                }
                var hit = args.Root.InputHitTest(args.Position);

                _pointers[args.TouchPointId] = pointer = new Pointer(Pointer.GetNextFreeId(),
                                                                     PointerType.Touch, _pointers.Count == 0);
                pointer.Capture(hit);
            }


            var target = pointer.Captured ?? args.Root;

            if (args.Type == RawPointerEventType.TouchBegin)
            {
                target.RaiseEvent(new PointerPressedEventArgs(target, pointer,
                                                              args.Root, args.Position, ev.Timestamp,
                                                              new PointerPointProperties(GetModifiers(args.InputModifiers, true),
                                                                                         PointerUpdateKind.LeftButtonPressed),
                                                              GetKeyModifiers(args.InputModifiers)));
            }

            if (args.Type == RawPointerEventType.TouchEnd)
            {
                _pointers.Remove(args.TouchPointId);
                using (pointer)
                {
                    target.RaiseEvent(new PointerReleasedEventArgs(target, pointer,
                                                                   args.Root, args.Position, ev.Timestamp,
                                                                   new PointerPointProperties(GetModifiers(args.InputModifiers, false),
                                                                                              PointerUpdateKind.LeftButtonReleased),
                                                                   GetKeyModifiers(args.InputModifiers), MouseButton.Left));
                }
            }

            if (args.Type == RawPointerEventType.TouchCancel)
            {
                _pointers.Remove(args.TouchPointId);
                using (pointer)
                    pointer.Capture(null);
            }

            if (args.Type == RawPointerEventType.TouchUpdate)
            {
                var modifiers = GetModifiers(args.InputModifiers, pointer.IsPrimary);
                target.RaiseEvent(new PointerEventArgs(InputElement.PointerMovedEvent, target, pointer, args.Root,
                                                       args.Position, ev.Timestamp,
                                                       new PointerPointProperties(GetModifiers(args.InputModifiers, true), PointerUpdateKind.Other),
                                                       GetKeyModifiers(args.InputModifiers)));
            }
        }
Beispiel #14
0
        /// <summary>
        /// Listens for non-client clicks and closes the menu when one is detected.
        /// </summary>
        /// <param name="e">The raw event.</param>
        private void ListenForNonClientClick(RawInputEventArgs e)
        {
            var mouse = e as RawMouseEventArgs;

            if (mouse?.Type == RawMouseEventType.NonClientLeftButtonDown)
            {
                Close();
            }
        }
Beispiel #15
0
        private void HandleRawInput(object sender, RawInputEventArgs e)
        {
            HidInputEventArgs hidArgs = e as HidInputEventArgs;

            if (hidArgs == null || HidInputEvent == null)
            {
                return;
            }
            HidInputEvent(sender, new HidEventArgs(hidArgs));
        }
        public int ReceiveEvent(RawInputEventArgs e)
        {
            if (e.VirtualKey == (ushort)keyAction)
            {
                SetStuff();

                return(0);
            }

            return(1);
        }
Beispiel #17
0
        private static void RawInputOnKeyPressed(object sender, RawInputEventArgs e)
        {
            if (e.KeyPressState == KeyPressState.Up && _watchKeys.ContainsKey(e.Key))
            {
                _watchKeys[e.Key]?.Invoke();
            }

            if (IsWaitingForScanner)
            {
                Settings.Default.ScannerId          = GetScannerId(e.Device);
                Settings.Default.ScannerDescription = e.Device.Description;
                Settings.Default.ScannerType        = e.Device.Type.ToString();
                Settings.Default.ScannerName        = e.Device.Name;
                Settings.Default.Save();

                IsWaitingForScanner = false;
                Messenger.Default.Broadcast(Messages.ScannerRegistered);
                _input.Clear();
                return;
            }

            //if (e.Device.Name == Settings.Default.ScannerName)
            //{
            if (e.KeyPressState != KeyPressState.Down)
            {
                return;
            }
            if (e.Key != Key.Enter)
            {
                if ((e.Key >= Key.A && e.Key <= Key.Z) || (e.Key >= Key.D0 && e.Key <= Key.D9))
                {
                    _input.Append((char)e.VirtualKey);
                }
            }
            else
            {
                if (_input.Length == 0)
                {
                    return;
                }
                _input.Remove(0, 1);
                //if (ExclusiveScan != null)
                //{
                //    ExclusiveScan.Invoke(_input.ToString());
                //    _input.Clear();
                //    return;
                //}
                //e.Handled = true;
                Messenger.Default.Broadcast(Messages.Scan, _input.ToString());
                _input.Clear();
            }
            //  TrapKey = true;
            //}
        }
            private void OnInput(RawInputEventArgs obj)
            {
                var mouseEvent = obj as RawMouseEventArgs;

                if (mouseEvent != null)
                {
                    mouseEvent.Position /= Scaling;
                }
                //TODO: Transform event coordinates
                Input?.Invoke(obj);
            }
Beispiel #19
0
        public int ReceiveEvent(RawInputEventArgs e)
        {
            if (e.VirtualKey == (ushort)keyAction)
            {
                R.NDB.TobiiModule.MouseEmulator.EyetrackerToMouse = false;
                R.NDB.TobiiModule.MouseEmulator.CursorVisible     = true;

                return(0);
            }

            return(1);
        }
        public int ReceiveEvent(RawInputEventArgs e)
        {
            if (e.VirtualKey == (ushort)keyAction)
            {
                Rack.DMIBox.TobiiModule.MouseEmulator = new MouseEmulator(new PointFilterBypass());
                Rack.DMIBox.TobiiModule.MouseEmulator.EyetrackerToMouse = true;
                Rack.DMIBox.TobiiModule.MouseEmulator.CursorVisible     = false;

                return(0);
            }

            return(1);
        }
Beispiel #21
0
 public int ReceiveEvent(RawInputEventArgs e)
 {
     if (e.VirtualKey == (ushort)keyMaj && e.KeyPressState == KeyPressState.Down)
     {
         Rack.DMIBox.NetytarSurface.Scale = new Scale(Rack.DMIBox.NetytarSurface.CheckedButton.Note.ToAbsNote(), ScaleCodes.maj);
         return(1);
     }
     if (e.VirtualKey == (ushort)keyMaj && e.KeyPressState == KeyPressState.Up)
     {
         Rack.DMIBox.NetytarSurface.Scale = new Scale(Rack.DMIBox.NetytarSurface.CheckedButton.Note.ToAbsNote(), ScaleCodes.min);
     }
     ;
     return(0);
 }
Beispiel #22
0
        void RawDevice_RawInput(object sender, RawInputEventArgs e)
        {
            if (devices.Contains(e.Handle))
            {
                DeviceStatus state     = devices[e.Handle];
                MouseData    mouseData = e.GetRawData() as MouseData;
                if (mouseData != null)
                {
                    UpdateMouse(mouseData, state);
                }
                else
                {
                    DeviceData deviceData = e.GetRawData() as DeviceData;
                    if (deviceData != null)
                    {
                        UpdatePen(deviceData, state);
                    }
                }

                if (state.ButtonState == DeviceState.None)
                {
                    return;
                }

                MouseContact contact = null;
                if (state.ButtonState == DeviceState.Down)
                {
                    contact = new MouseContact(state);
                    //Debug.WriteLine("Down: " + contact);
                    contacts.Add(contact);
                }
                else if ((state.ButtonState == DeviceState.Move || state.ButtonState == DeviceState.Up) && contacts.Contains(e.Handle))
                {
                    contact = contacts[e.Handle];
                    //Debug.WriteLine("Move: " + contact);
                    contact.Update(state);
                }
                if (contact != null)
                {
                    inputProvider.EnqueueContact(contact);
                }
                if (state.ButtonState == DeviceState.Up)
                {
                    contact = contacts[e.Handle];
                    contact.Update(state);
                    //Debug.WriteLine("Up: " + contact);
                    contacts.Remove(e.Handle);
                }
            }
        }
Beispiel #23
0
        public void ProcessRawEvent(RawInputEventArgs ev)
        {
            var args = (RawTouchEventArgs)ev;

            if (!_pointers.TryGetValue(args.TouchPointId, out var pointer))
            {
                if (args.Type == RawPointerEventType.TouchEnd)
                {
                    return;
                }
                var hit = args.Root.InputHitTest(args.Position);

                _pointers[args.TouchPointId] = pointer = new Pointer(Pointer.GetNextFreeId(),
                                                                     PointerType.Touch, _pointers.Count == 0, hit);
            }


            var target = pointer.GetEffectiveCapture() ?? args.Root;

            if (args.Type == RawPointerEventType.TouchBegin)
            {
                var modifiers = GetModifiers(args.InputModifiers, false);
                target.RaiseEvent(new PointerPressedEventArgs(target, pointer,
                                                              args.Root, args.Position, new PointerPointProperties(modifiers),
                                                              modifiers));
            }

            if (args.Type == RawPointerEventType.TouchEnd)
            {
                _pointers.Remove(args.TouchPointId);
                var modifiers = GetModifiers(args.InputModifiers, pointer.IsPrimary);
                using (pointer)
                {
                    target.RaiseEvent(new PointerReleasedEventArgs(target, pointer,
                                                                   args.Root, args.Position, new PointerPointProperties(modifiers),
                                                                   modifiers, pointer.IsPrimary ? MouseButton.Left : MouseButton.None));
                }
            }

            if (args.Type == RawPointerEventType.TouchUpdate)
            {
                var modifiers = GetModifiers(args.InputModifiers, pointer.IsPrimary);
                target.RaiseEvent(new PointerEventArgs(InputElement.PointerMovedEvent, target, pointer, args.Root,
                                                       args.Position, new PointerPointProperties(modifiers), modifiers));
            }
        }
Beispiel #24
0
 /// <summary>
 /// Processes a raw input event.
 /// </summary>
 /// <param name="e">The raw input event.</param>
 public void ProcessInput(RawInputEventArgs e)
 {
     if (e.Device != null && e.Device is IKeyboardDevice)
     {
         try
         {
             // This got broken somehow
             underlyingInputManager.ProcessInput(e);
         }
         catch (InvalidOperationException)
         {
         }
     }
     else
     {
         underlyingInputManager.ProcessInput(e);
     }
 }
Beispiel #25
0
        private void ProcessRawEvent(RawInputEventArgs e)
        {
            IInputElement element = FocusedElement;

            if (element != null)
            {
                var keyInput = e as RawKeyEventArgs;
                if (keyInput != null)
                {
                    switch (keyInput.Type)
                    {
                    case RawKeyEventType.KeyDown:
                    case RawKeyEventType.KeyUp:
                        var routedEvent = keyInput.Type == RawKeyEventType.KeyDown
                                ? InputElement.KeyDownEvent
                                : InputElement.KeyUpEvent;

                        KeyEventArgs ev = new KeyEventArgs
                        {
                            RoutedEvent = routedEvent,
                            Device      = this,
                            Key         = keyInput.Key,
                            Modifiers   = keyInput.Modifiers,
                            Source      = element,
                        };

                        element.RaiseEvent(ev);
                        break;
                    }
                }
                var text = e as RawTextInputEventArgs;
                if (text != null)
                {
                    element.RaiseEvent(new TextInputEventArgs()
                    {
                        Device      = this,
                        Text        = text.Text,
                        Source      = element,
                        RoutedEvent = InputElement.TextInputEvent
                    });
                }
            }
        }
        void HandleInput(RawInputEventArgs args)
        {
            if (args is RawKeyEventArgs rawKeyEventArgs)
            {
                // swap cmd and ctrl
                var modifier = rawKeyEventArgs.Modifiers & ~InputModifiers.Control & ~InputModifiers.Windows;
                if (rawKeyEventArgs.Modifiers.HasFlag(InputModifiers.Windows))
                {
                    modifier |= InputModifiers.Control;
                }
                if (rawKeyEventArgs.Modifiers.HasFlag(InputModifiers.Control))
                {
                    modifier |= InputModifiers.Windows;
                }

                rawKeyEventArgs.Modifiers = modifier;
            }

            originalInputEventHanlder(args);
        }
Beispiel #27
0
        public int ReceiveEvent(RawInputEventArgs e)
        {
            if (e.VirtualKey == (ushort)keyStart)
            {
                R.UserSettings.AutoStrum = true;

                R.NDB.StartAutostrum(R.UserSettings.AutoStrumBPM);

                return(0);
            }
            if (e.VirtualKey == (ushort)keyStop)
            {
                R.UserSettings.AutoStrum = false;

                R.NDB.StopAutostrum();

                return(0);
            }

            return(1);
        }
Beispiel #28
0
        public int ReceiveEvent(RawInputEventArgs e)
        {
            if (R.NDB.keyboardEmulator)
            {
                if (e.VirtualKey == (ushort)space && e.KeyPressState == KeyPressState.Down && !isDown)
                {
                    R.NDB.KeyDown = true;
                    isDown        = true;
                    return(0);
                }
                if (e.VirtualKey == (ushort)space && e.KeyPressState == KeyPressState.Up)
                {
                    R.NDB.KeyDown = false;
                    isDown        = false;
                    return(0);
                }
                ;
            }

            return(1);
        }
Beispiel #29
0
        public int ReceiveEvent(RawInputEventArgs e)
        {
            returnVal = 0;

            if (Rack.DMIBox.NetytarControlMode == NetytarControlModes.Keyboard)
            {
                if (e.VirtualKey == (ushort)keyBlow && e.KeyPressState == KeyPressState.Down)
                {
                    blowing   = true;
                    returnVal = 1;
                    Rack.DMIBox.NetytarMainWindow.BreathSensorValue = 127;
                }
                else if (e.VirtualKey == (ushort)keyBlow && e.KeyPressState == KeyPressState.Up)
                {
                    blowing   = false;
                    returnVal = 1;
                    Rack.DMIBox.NetytarMainWindow.BreathSensorValue = 0;
                }
                Rack.DMIBox.Blow = blowing;
            }

            return(returnVal);
        }
Beispiel #30
0
        private static void RawInputOnKeyPressed(object sender, RawInputEventArgs e)
        {
            if (e.KeyPressState == KeyPressState.Up && _watchKeys.ContainsKey(e.Key))
            {
                _watchKeys[e.Key]?.Invoke();
            }

            if (IsWaitingForScanner)
            {
                Settings.Default.ScannerId   = e.Device.Name;
                Settings.Default.ScannerName = e.Device.Description;
                Settings.Default.Save();
                IsWaitingForScanner = false;
                Messenger.Default.Broadcast(Messages.ScannerRegistered);
                _input.Clear();
                return;
            }
            var scanner = Settings.Default.ScannerId;

            if (scanner == e.Device.Name)
            {
                if (e.KeyPressState != KeyPressState.Down)
                {
                    return;
                }
                if (e.Key != Key.Enter)
                {
                    _input.Append((char)e.VirtualKey);
                }
                else
                {
                    Messenger.Default.Broadcast(Messages.Scan, _input.ToString());
                    _input.Clear();
                }
            }
        }
Beispiel #31
0
        public int ReceiveEvent(RawInputEventArgs e)
        {
            if (e.VirtualKey == (ushort)keyStartEmulate)
            {
                eyeTrackerToMouse   = true;
                cursorVisible       = false;
                autoScrollerEnabled = true;

                SetStuff();

                return(0);
            }
            else if (e.VirtualKey == (ushort)keyStopEmulate)
            {
                eyeTrackerToMouse   = false;
                cursorVisible       = true;
                autoScrollerEnabled = false;

                SetStuff();

                return(0);
            }
            return(1);
        }
 private void RawInput_ButtonDown(object sender, RawInputEventArgs e)
 {
     btnTalkKey.Content = App.Settings.Current.Voice.TalkKey = e.Button;
     RawInput.ButtonDown -= RawInput_ButtonDown;
     e.Handled = true;
 }
 private void OnKeyPressed(object sender, RawInputEventArgs e)
 {
     Event = e;
     DeviceCount = _rawInput.NumberOfKeyboards;
     e.Handled = (ShouldHandle.IsChecked == true);
 }