RawGameController 類別

定義

表示任何類型的遊戲控制器。

public ref class RawGameController sealed : IGameControllerBatteryInfo
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 262144)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class RawGameController final : IGameControllerBatteryInfo
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 262144)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class RawGameController : IGameControllerBatteryInfo
Public NotInheritable Class RawGameController
Implements IGameControllerBatteryInfo
繼承
Object Platform::Object IInspectable RawGameController
屬性
實作

Windows 需求

裝置系列
Windows 10 Creators Update (已於 10.0.15063.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v4.0 引進)

範例

下列程式碼片段示範如何迴圈執行 RawGameController.RawGameControllers 清單,並將每個 RawGameController 新增至向量。 您必須將鎖定放在向量上,因為控制器隨時可能會變更, (控制器可能會中斷連線或重新連線,例如) 。

#include <concrt.h>
#include <winrt/Windows.Gaming.Input.h>
using namespace winrt;
using namespace Windows::Gaming::Input;
...
std::vector<RawGameController> myRawGameControllers;
concurrency::critical_section myLock{};

for (auto const& rawGameController : RawGameController::RawGameControllers())
{
    // Test whether the raw game controller is already in myRawGameControllers; if it isn't, add it.
    concurrency::critical_section::scoped_lock lock{ myLock };
    auto it{ std::find(begin(myRawGameControllers), end(myRawGameControllers), rawGameController) };

    if (it == end(myRawGameControllers))
    {
        // This code assumes that you're interested in all raw game controllers.
        myRawGameControllers.push_back(rawGameController);
    }
}

備註

無法直接建立 RawGameController 類別的 實例;相反地,類別的實例是透過 RawGameController.RawGameControllers 屬性擷取,其中列出所有已連線的遊戲控制器或 透過 RawGameController.RawGameControllerAdded 事件擷取。

RawGameController上可用的所有輸入都會公開為未命名按鈕、切換和軸的簡單陣列。 使用這個類別,您可以讓客戶建立自訂輸入對應,不論他們所使用的控制器類型為何。

您必須自行建立這些陣列,然後使用 GetCurrentReading 填入這些陣列,以判斷按鈕、切換和軸的狀態。 如需詳細資訊,請參閱該函式的檔。

如需如何使用RawGameController類別的詳細資訊,請參閱原始遊戲控制器

版本歷程記錄

Windows 版本 SDK 版本 已新增值
1709 16299 DisplayName
1709 16299 NonRoamableId
1709 16299 SimpleHapticsControllers

屬性

AxisCount

原始遊戲控制器上的座標軸數目。

ButtonCount

原始遊戲控制器上的按鈕數目。

DisplayName

硬體所提供的控制器名稱。

ForceFeedbackMotors

原始遊戲控制器中的強制回饋馬達清單。

HardwareProductId

原始遊戲控制器的硬體產品識別碼。

HardwareVendorId

原始遊戲控制器的硬體廠商識別碼。

Headset

附加至原始遊戲控制器的音訊頭戴式裝置。

IsWireless

取得值,這個值表示原始遊戲控制器的無線狀態。

NonRoamableId

識別控制器的唯一識別碼。 只要控制器已連線,識別碼永遠不會變更。

RawGameControllers

所有已連線原始遊戲控制器的清單。

SimpleHapticsControllers

SimpleHapticsController物件的集合,代表裝置上所有可用的觸覺回饋馬達。

SwitchCount

原始遊戲控制器上的交換器數目。

User

與原始遊戲控制器相關聯的使用者。

方法

FromGameController(IGameController)

以原始遊戲控制器的形式傳回指定的遊戲控制器。

GetButtonLabel(Int32)

擷取指定按鈕的按鈕標籤。

GetCurrentReading(Boolean[], GameControllerSwitchPosition[], Double[])

取得原始遊戲控制器狀態的快照集。

GetSwitchKind(Int32)

取得原始遊戲控制器上指定參數的類型。

TryGetBatteryReport()

取得原始遊戲控制器目前電池狀態的相關資訊。

事件

HeadsetConnected

當頭戴裝置附加至原始遊戲控制器時發出訊號。

HeadsetDisconnected

當頭戴裝置與原始遊戲控制器中斷連線時發出訊號。

RawGameControllerAdded

當新的原始遊戲控制器連線時發出訊號。

RawGameControllerRemoved

當原始遊戲控制器中斷連線時發出訊號。

UserChanged

當使用者與原始遊戲控制器相關聯的使用者已變更時發出訊號。

適用於

另請參閱