コード例 #1
0
        protected override void HandleEvent(input_event ev)
        {
            if (ev.Type == EvType.EV_ABS)
            {
                if (ev.Axis == AbsAxis.ABS_X)
                {
                    _currentX    = ev.value;
                    _hasMovement = true;
                }

                if (ev.Axis == AbsAxis.ABS_Y)
                {
                    _currentY    = ev.value;
                    _hasMovement = true;
                }
            }

            if (ev.Type == EvType.EV_KEY)
            {
                if (ev.Key == EvKey.BTN_TOUCH)
                {
                    _pressAction = ev.value != 0;
                }
            }

            if (ev.Type == EvType.EV_SYN)
            {
                if (_pressAction != null)
                {
                    RaiseEvent(_pressAction == true ? RawPointerEventType.TouchBegin : RawPointerEventType.TouchEnd,
                               ev.Timestamp);
                }
                else if (_hasMovement)
                {
                    RaiseEvent(RawPointerEventType.TouchUpdate, ev.Timestamp);
                }
                _hasMovement = false;
                _pressAction = null;
            }
        }
コード例 #2
0
        public unsafe static void SetKey(ushort KeyCode, bool Pressed)
        {
            input_event keyEv = new input_event();
            input_event synEv = new input_event();

            keyEv.type  = EV_KEY;
            keyEv.code  = KeyCode;
            keyEv.value = Pressed ? 1 : 0;

            synEv.type  = EV_SYN;
            synEv.code  = SYN_REPORT;
            synEv.value = 0;

            BCM2835.Native.write(fd, (void *)&keyEv, sizeof(input_event));

            if (keyEv.code != LinuxKeyCodes.KEY_LEFTSHIFT && keyEv.code != LinuxKeyCodes.KEY_RIGHTSHIFT &&
                keyEv.code != LinuxKeyCodes.KEY_LEFTALT && keyEv.code != LinuxKeyCodes.KEY_RIGHTALT &&
                keyEv.code != LinuxKeyCodes.KEY_LEFTCTRL && keyEv.code != LinuxKeyCodes.KEY_RIGHTCTRL)
            {
                BCM2835.Native.write(fd, (void *)&synEv, sizeof(input_event));
            }
        }
コード例 #3
0
 protected abstract void HandleEvent(input_event ev);
コード例 #4
0
        private static 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;
                }
                Console.WriteLine($"relative x->{_x} y->{_y}");
            }
            else 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;
                }

                Console.WriteLine($"absolute x->{_x} y->{_y}");
            }
            else 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;
                }

                Console.WriteLine($"key button->{type}");
            }
            else
            {
                Console.WriteLine($"other type->{(EvType)ev.type} code->{ev.code} value->{ev.value}");
            }
        }