# 飛行桿Flight stick

• 如何收集所連接飛行桿及其使用者的清單how to gather a list of connected flight sticks and their users
• 如何偵測已新增或移除飛行桿how to detect that a flight stick has been added or removed
• 如何讀取來自一或多個飛行桿的輸入how to read input from one or more flight sticks
• 飛行搖桿如何當成 UI 瀏覽裝置使用how flight sticks behave as UI navigation devices

## 概觀Overview

Xbox One 飛行桿配備下列控制項︰Xbox One flight sticks are equipped with the following controls:

• 可翻滾、俯仰及偏擺的可彎式類比搖桿A twistable analog joystick capable of roll, pitch, and yaw
• 一個類比節流閥An analog throttle
• 兩個開火按鈕Two fire buttons
• 一個數位控制帽切換裝置An 8-way digital hat switch

UpUp 搖桿向上Joystick up
DownDown 搖桿向下Joystick down
LeftLeft 搖桿向左Joystick left
RightRight 搖桿向右Joystick right

## 偵測和追蹤飛行桿Detect and track flight sticks

### 輪詢飛行桿Polling the flight stick

``````auto flightStick = myFlightSticks->GetAt(0);
``````

### 讀取搖桿和節流閥輸入Reading the joystick and throttle input

``````// Each variable will contain a value between -1.0 and 1.0.
``````

``````// Choose a deadzone. Readings inside this radius are ignored.

// Pythagorean theorem: For a right triangle, hypotenuse^2 = (opposite side)^2 + (adjacent side)^2
float oppositeSquared = pitch * pitch;
float adjacentSquared = roll * roll;

// Accept and process input if true; otherwise, reject and ignore it.
{
// Input accepted, process it.
}
``````

### 讀取按鈕與控制帽切換裝置Reading the buttons and hat switch

``````if (FlightStickButtons::FirePrimary == (reading.Buttons & FlightStickButtons::FirePrimary))
{
// FirePrimary is pressed.
}
``````

``````if (FlightStickButtons::None == (reading.Buttons & FlightStickButtons::FirePrimary))
{
// FirePrimary is released (not pressed).
}
``````

``````if (GameControllerSwitchPosition::Up == (reading.HatSwitch & GameControllerSwitchPosition::Up))
{
// The hat switch is in the up position.
}
``````

``````if (GameControllerSwitchPosition::Center == (reading.HatSwitch & GameControllerSwitchPosition::Center))
{
// The hat switch is in the center position.
}
``````