public void PollJoystick()
        {
            while (true)
            {
                joystick.Poll();
                JoystickUpdate[] datas = joystick.GetBufferedData();
                foreach (JoystickUpdate state in datas)
                {
                    if (state.Offset >= JoystickOffset.Buttons0 && state.Offset <= JoystickOffset.Buttons127)
                    {
                        if (state.Value == 128)
                        {
                            // pressed down
                            JoystickButtonPressedEventArgs args = new JoystickButtonPressedEventArgs();
                            args.ButtonOffset = state.RawOffset;
                            args.TimeStamp    = DateTime.Now;
                            args.offset       = state.Offset;
                            OnJoystickButtonPressed(args);

                            if (state.RawOffset == startButtonOffset)
                            {
                                OnJoystickStartButtonPressed(args);
                            }
                            else if (state.RawOffset == lapButtonOffset)
                            {
                                OnJoystickLapButtonPressed(args);
                            }
                        }
                    }
                }

                Thread.Sleep(10);
            }
        }
        protected virtual void OnJoystickStartButtonPressed(JoystickButtonPressedEventArgs e)
        {
            EventHandler <JoystickButtonPressedEventArgs> handler = JoystickStartButtonPressed;

            if (handler != null)
            {
                handler(this, e);
            }
        }
示例#3
0
        void onJoystickButton(object sender, EventArgs e)
        {
            JoystickButtonPressedEventArgs eventArg = (JoystickButtonPressedEventArgs)e;
            int button  = (int)eventArg.offset - (int)JoystickOffset.Buttons0 + 1;
            var focused = FindFocusedControl(this);

            if (focused is TextBox)
            {
                pictureBox1.Invoke((MethodInvoker) delegate {
                    ((TextBox)focused).Text = "" + button;
                });
            }
        }