Пример #1
0
 public static extern int libevdev_next_event(IntPtr dev, int flags, out input_event ev);
Пример #2
0
        private void ProcessEvent(EvDevDevice device, input_event ev)
        {
            if (ev.type == (short)EvType.EV_REL)
            {
                if (ev.code == (short)AxisEventCode.REL_X)
                {
                    _x = Math.Min(_width, Math.Max(0, _x + ev.value));
                }
                else if (ev.code == (short)AxisEventCode.REL_Y)
                {
                    _y = Math.Min(_height, Math.Max(0, _y + ev.value));
                }
                else
                {
                    return;
                }
                Event?.Invoke(new RawMouseEventArgs(LinuxFramebufferPlatform.MouseDevice,
                                                    LinuxFramebufferPlatform.Timestamp,
                                                    LinuxFramebufferPlatform.TopLevel.InputRoot, RawMouseEventType.Move, new Point(_x, _y),
                                                    InputModifiers.None));
            }
            if (ev.type == (int)EvType.EV_ABS)
            {
                if (ev.code == (short)AbsAxis.ABS_X && device.AbsX.HasValue)
                {
                    _x = TranslateAxis(device.AbsX.Value, ev.value, _width);
                }
                else if (ev.code == (short)AbsAxis.ABS_Y && device.AbsY.HasValue)
                {
                    _y = TranslateAxis(device.AbsY.Value, ev.value, _height);
                }
                else
                {
                    return;
                }
                Event?.Invoke(new RawMouseEventArgs(LinuxFramebufferPlatform.MouseDevice,
                                                    LinuxFramebufferPlatform.Timestamp,
                                                    LinuxFramebufferPlatform.TopLevel.InputRoot, RawMouseEventType.Move, new Point(_x, _y),
                                                    InputModifiers.None));
            }
            if (ev.type == (short)EvType.EV_KEY)
            {
                RawMouseEventType?type = null;
                if (ev.code == (ushort)EvKey.BTN_LEFT)
                {
                    type = ev.value == 1 ? RawMouseEventType.LeftButtonDown : RawMouseEventType.LeftButtonUp;
                }
                if (ev.code == (ushort)EvKey.BTN_RIGHT)
                {
                    type = ev.value == 1 ? RawMouseEventType.RightButtonDown : RawMouseEventType.RightButtonUp;
                }
                if (ev.code == (ushort)EvKey.BTN_MIDDLE)
                {
                    type = ev.value == 1 ? RawMouseEventType.MiddleButtonDown : RawMouseEventType.MiddleButtonUp;
                }
                if (!type.HasValue)
                {
                    return;
                }

                Event?.Invoke(new RawMouseEventArgs(LinuxFramebufferPlatform.MouseDevice,
                                                    LinuxFramebufferPlatform.Timestamp,
                                                    LinuxFramebufferPlatform.TopLevel.InputRoot, type.Value, new Point(_x, _y), default(InputModifiers)));
            }
        }