GetCurrentStatus() public method

Get joystick's status.

Before using this method the joystick object needs to be initialized using Init method or Joystick(int) constructor.

The requested joystick is not connected to the system. Joystick was not initialized.
public GetCurrentStatus ( ) : Status
return Status
Ejemplo n.º 1
0
        /// <summary>
        /// Scanning routine for device input
        /// </summary>
        /// <param name="sender">Event Source</param>
        /// <param name="e">Event arguments</param>
        private void Scan(object sender, DoWorkEventArgs e)
        {
            Joystick joystick = new Joystick(0);
            Joystick.Status status;
            String buttons = "";
            BackgroundWorker worker = (BackgroundWorker) sender;
            while (!worker.CancellationPending)
            {
                status = joystick.GetCurrentStatus();
                buttons = status.Buttons.ToString();
                // action button
                if (buttons != "0")
                {
                    List<string> inputs = buttons.Split(new[] { "Button", ", " }, StringSplitOptions.RemoveEmptyEntries).ToList();

                    SetClickCallBack callBack = SetClick;
                    for (int i = 0; i < Buttons.Length; i++)
                    {
                        Buttons[i].Dispatcher.Invoke(callBack,
                            new object[] {i.ToString(), 
                                inputs.Contains((i+1).ToString())});
                    }
                }
                else
                {
                    SetClickCallBack callBack = SetClick;
                    for (int i = 0; i < Buttons.Length; i++)
                    {
                        Buttons[i].Dispatcher.Invoke(callBack,
                            new object[] {i.ToString(), false});
                    }
                }

                try
                {
                    // navigation button
                    switch ((int)status.XAxis)
                    {
                        case -1:
                            Left.Dispatcher.Invoke(() =>
                                {
                                    Left.Click = true;
                                }
                                );
                            break;
                        case 1:
                            Left.Dispatcher.Invoke(() =>
                                {
                                    Right.Click = true;
                                }
                                );
                            break;
                        default:
                            Left.Dispatcher.Invoke(() =>
                                {
                                    Left.Click = false;
                                }
                                );
                            Left.Dispatcher.Invoke(() =>
                                {
                                    Right.Click = false;
                                }
                                );
                            break;
                    }
                    switch ((int)status.YAxis)
                    {
                        case -1:
                            Up.Dispatcher.Invoke(() =>
                                {
                                    Up.Click = true;
                                }
                                );
                            break;
                        case 1:
                            Down.Dispatcher.Invoke(() =>
                                {
                                    Down.Click = true;
                                }
                                );
                            break;
                        default:
                            Up.Dispatcher.Invoke(() =>
                                {
                                    Up.Click = false;
                                }
                                );
                            Down.Dispatcher.Invoke(() =>
                                {
                                    Down.Click = false;
                                }
                                );
                            break;
                    }
                }
                catch (TaskCanceledException )
                {
                    break;
                }

            }
        }