Пример #1
0
 public virtual void KeyStateChanged(G13KeyState newState)
 {
 }
Пример #2
0
        protected void DecodeData(DeviceData data)
        {
            G13KeyState state = new G13KeyState();

            var profile = ProfileRunner;

            if (profile == null || !profile.IsRunning)
            {
                return;
            }

            if (DeviceData.ReadStatus.Success == data.Status)
            {
                var bytes = data.Bytes;

                var reportId = bytes[0];
                var j        = new JoystickPosition(bytes[1] - 0x80, bytes[2] - 0x80);

                if (j.X != joystick.X || j.Y != joystick.Y)
                {
                    joystick = j;
                    profile.JoystickChanged(j);
                }

                state.B0 = bytes[3];
                state.B1 = bytes[4];
                state.B2 = bytes[5] < 0x80 ? bytes[5] : (byte)(bytes[5] - 0x80);
                state.B3 = bytes[6];
                state.B4 = bytes[7] < 0x80 ? bytes[7] : (byte)(bytes[7] - 0x80);

                profile.KeyStateChanged(state);

                var keys    = currentState.UL ^ state.UL;
                var pressed = (keys & state.UL) > 0;
                currentState = state;

                if (keys > 0)
                {
                    if (pressed)
                    {
                        if (profile.SingleKeyEvents)
                        {
                            FireSingleKey(profile, keys, true);
                        }
                        else
                        {
                            profile.KeysPressed(keys);
                        }
                    }
                    else
                    {
                        if (profile.SingleKeyEvents)
                        {
                            FireSingleKey(profile, keys, false);
                        }
                        else
                        {
                            profile.KeysReleased(keys);
                        }
                    }
                }
            }
        }