Beispiel #1
0
        protected virtual void OnJoystickRotationYchange(JoystickButtonPressedEventArgs e)
        {
            EventHandler <JoystickButtonPressedEventArgs> handler = JoystickRotationYchange;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Beispiel #2
0
        protected virtual void OnJoystickXchange(JoystickButtonPressedEventArgs e)
        {
            EventHandler <JoystickButtonPressedEventArgs> handler = JoystickXchange;

            //EventHandler<JoystickButtonPressedEventArgs> handler = Volatile.Read(ref JoystickXchange);
            if (handler != null)
            {
                handler(this, e);
            }
        }
Beispiel #3
0
        public void PollJoystick()
        {
            while (!_QuitPolling)
            {
                if (!directInput.IsDeviceAttached(joystick.Information.InstanceGuid))
                {
                    MessageBox.Show("Потеряна связь с джойстиком", "Джойстик", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    break;
                }

                joystick.Poll();
                JoystickUpdate[] datas = joystick.GetBufferedData();
                JoystickButtonPressedEventArgs args    = new JoystickButtonPressedEventArgs();
                JoystickPacket_CAEventArgs     argc_CA = new JoystickPacket_CAEventArgs();
                foreach (JoystickUpdate state in datas)
                {
                    skip_data = false;
                    switch (state.Offset)
                    {
                    case JoystickOffset.RotationX:

                        args.Value = state.Value;
                        OnJoystickRotationXchange(args);
                        break;

                    case JoystickOffset.RotationY:
                        args.Value = state.Value;
                        OnJoystickRotationYchange(args);
                        break;

                    case JoystickOffset.X:
                        packet_CA.axis_X = (byte)(state.Value / 256);
                        args.Value       = state.Value;
                        OnJoystickXchange(args);
                        break;

                    case JoystickOffset.Y:
                        packet_CA.axis_Y = (byte)(state.Value / 256);
                        args.Value       = state.Value;
                        OnJoystickYchange(args);
                        break;

                    case JoystickOffset.Sliders0:
                        packet_CA.axis_Z = (byte)(state.Value / 256);
                        args.Value       = state.Value;
                        OnJoystickZchange(args);
                        break;

                    case JoystickOffset.Buttons0:
                        packet_CA.button1 = (state.Value > 0) ? (byte)1 : (byte)0;
                        break;

                    default:
                        skip_data = true;
                        break;
                    }
                }
                if (datas.Length > 0 && !skip_data)
                {
                    argc_CA.packet_CA = packet_CA;
                    OnPacket_CA_change(argc_CA);
                }


                Thread.Sleep(10);
            }
        }