LegacyGipGameControllerProvider 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
公開一組屬性和功能來管理遊戲配件,例如遊戲板和頭戴式裝置,這些裝置使用 GIP (遊戲輸入通訊協定) 通訊協定。
重要
存取此類別需要宣告 xboxAccessoryManagement 功能
警告
這些 API 會影響系統上的所有遊戲,如果誤用,可能會導致配件發生問題。 Microsoft 建議只使用這些 API 來管理您已開發的硬體。
public ref class LegacyGipGameControllerProvider sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Gaming.Input.GamingInputPreviewContract, 131072)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class LegacyGipGameControllerProvider final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Gaming.Input.GamingInputPreviewContract), 131072)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class LegacyGipGameControllerProvider
Public NotInheritable Class LegacyGipGameControllerProvider
- 繼承
- 屬性
Windows 需求
裝置系列 |
Windows Desktop Extension SDK (已於 10.0.23665.0 引進)
|
API contract |
Windows.Gaming.Input.GamingInputPreviewContract (已於 v2.0 引進)
|
範例
讀取控制器的屬性
public void EnumerateControllerProperties()
{
foreach (Gamepad gamepad in Gamepad.Gamepads)
{
// Create the provider
LegacyGipGameControllerProvider legacyGipGameControllerProvider =
LegacyGipGameControllerProvider.FromGameController(gamepad);
if (legacyGipGameControllerProvider == null)
{
// Not every gamepad is a legacy GIP game controller, continue enumerating
continue;
}
// Check properties
GameControllerBatteryChargingState chargeState =
legacyGipGameControllerProvider.BatteryChargingState;
GameControllerBatteryKind batteryKind =
legacyGipGameControllerProvider.BatteryKind;
GameControllerBatteryLevel batteryLevel =
legacyGipGameControllerProvider.BatteryLevel;
bool isOldFirmwareCorrupted =
legacyGipGameControllerProvider.IsFirmwareCorrupted;
bool isNewFirmwareCorrupted =
legacyGipGameControllerProvider.GetDeviceFirmwareCorruptionState()
!= GameControllerFirmwareCorruptReason.NotCorrupt;
bool isSynthetic = legacyGipGameControllerProvider.IsSyntheticDevice;
byte[] extendedDeviceInfo = legacyGipGameControllerProvider.GetExtendedDeviceInfo();
// Check for a particular GIP interface
bool supportsSomeCustomInterface =
legacyGipGameControllerProvider.IsInterfaceSupported(
new Guid(
0xaaaaaaaa, 0xbbbb, 0xcccc, 0xe, 0xf, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6));
IReadOnlyList<string> preferredTypes =
legacyGipGameControllerProvider.PreferredTypes;
bool isGamepad = preferredTypes.Contains("Windows.Xbox.Input.Gamepad");
bool isHeadset = preferredTypes.Contains("Windows.Xbox.Input.Headset");
// Change the LED to half brightness
legacyGipGameControllerProvider.SetHomeLedIntensity(50);
}
}
重新對應按鈕
void RemapButtons(IGameController controller, IGameControllerProvider controllerProvider)
{
LegacyGipGameControllerProvider legacyGipGameControllerProvider =
LegacyGipGameControllerProvider.FromGameControllerProvider(controllerProvider);
// Retrieve all current remappings set for standard controllers
IReadOnlyDictionary<RemappingButtonCategory, object> currentMappings =
legacyGipGameControllerProvider.GetStandardControllerButtonRemapping(
controller.User, false);
// Swap two of the buttons
Dictionary<RemappingButtonCategory, object> remaps =
new Dictionary<RemappingButtonCategory, object>();
// Duplicates are not allowed. Swap two of the buttons
UInt64 currentButtonMappings =
(UInt64)currentMappings[RemappingButtonCategory.ButtonSettings];
// Isolate the buttons we want to remap
UInt64 lastButton = (currentButtonMappings & 0xf000000000000000);
UInt64 secondLastButton = currentButtonMappings & 0x0f00000000000000;
// Swap their positions
UInt64 newMapping = (lastButton >> 4) | (secondLastButton << 4);
// Recombine with the original mappings
UInt64 newButtonMappings = (currentButtonMappings & 0x00ffffffffffffff) | newMapping;
// Add the new button remappings to the mapping dictionary
remaps.Add(RemappingButtonCategory.ButtonSettings, newButtonMappings);
// Update controller mapping
legacyGipGameControllerProvider.SetStandardControllerButtonRemapping(
controller.User, false, newButtonMappings);
}
Copilot 設定
public void CopilotSample(GipGameControllerProvider pilotProvider,
GipGameControllerProvider copilotProvider)
{
// Establish a copilot pairing for the given pilot and copilot providers
string pilotId = GameControllerProviderInfo.GetProviderId(pilotProvider);
string copilotId = GameControllerProviderInfo.GetProviderId(copilotProvider);
User user = User.GetDefault();
LegacyGipGameControllerProvider.PairPilotToCopilot(user, pilotId,
copilotId);
// Read copilot properties
LegacyGipGameControllerProvider.IsPilot(user, pilotId); // Returns copilotId
LegacyGipGameControllerProvider.IsPilot(user, copilotId); // Returns null
LegacyGipGameControllerProvider.IsCopilot(user, pilotId); // Returns null
LegacyGipGameControllerProvider.IsCopilot(user, copilotId); // Returns pilotId
// Removes the pairing for both controllers
LegacyGipGameControllerProvider.ClearPairing(user, pilotId);
// Also removes the pairing for both controllers (unnecessary since the pairing was already removed)
LegacyGipGameControllerProvider.ClearPairing(user, copilotId);
}
頭戴式裝置管理
public void SetupHeadset(IGameControllerProvider headsetProvider)
{
LegacyGipGameControllerProvider legacyGipGameControllerProvider =
LegacyGipGameControllerProvider.FromGameControllerProvider(headsetProvider);
// Reset the device
legacyGipGameControllerProvider.ExecuteCommand(DeviceCommand.Reset);
// Check the smart mute level
byte[] smartMuteBuffer =
legacyGipGameControllerProvider.GetHeadsetOperation(HeadsetOperation.SmartMute);
HeadsetLevel smartMuteValue = (HeadsetLevel)smartMuteBuffer[0];
// Set bass boost to 3db
byte[] bassBuffer = BitConverter.GetBytes((UInt32)3);
legacyGipGameControllerProvider.SetHeadsetOperation(HeadsetOperation.BassBoostGain,
bassBuffer);
}
屬性
AppCompatVersion |
取得 GIP (遊戲輸入通訊協定) 驅動程式所報告的應用程式相容性版本。 |
BatteryChargingState |
取得控制器的電池充電狀態。 |
BatteryKind |
取得控制器的電池種類。 |
BatteryLevel |
取得控制器的電池電量。 |
IsFirmwareCorrupted |
傳回控制器韌體是否損毀。 |
IsSyntheticDevice |
傳回控制器是綜合或實體裝置。 |
PreferredTypes |
取得控制器所報告的 GIP (遊戲輸入通訊協定) 類型集合。 |
方法
ClearPairing(User, String) |
拿掉指定使用者controllerId的任何 copilot 配對。 |
ExecuteCommand(DeviceCommand) |
在舊版 GIP (遊戲輸入通訊協定) 頭戴式裝置上執行命令。 |
FromGameController(IGameController) |
為指定的控制器建構 LegacyGipGameControllerProvider 。 |
FromGameControllerProvider(IGameControllerProvider) |
為指定的控制器提供者建構 LegacyGipGameControllerProvider 。 |
GetDeviceFirmwareCorruptionState() |
擷取裝置韌體是否損毀的狀態,如果是的話,則以何種方式擷取。 |
GetExtendedDeviceInfo() |
擷取裝置的標識碼資訊。 |
GetHeadsetOperation(HeadsetOperation) |
根據 |
GetStandardControllerButtonRemapping(User, Boolean) |
擷取用戶標準遊戲板的按鈕和軸對應。 |
IsCopilot(User, String) |
如果此控制器是 copilot,擷取試驗控制器的標識碼。 |
IsInterfaceSupported(Guid) |
查詢控制器是否支援指定的 GIP (遊戲輸入通訊協定) 介面 guid。 |
IsPilot(User, String) |
如果這個控制器是試驗,擷取 copilot 控制器的標識碼。 |
PairPilotToCopilot(User, String, String) |
為指定的使用者配對指定的試驗和 Copilot 控制器。 |
SetHeadsetOperation(HeadsetOperation, Byte[]) |
設定頭戴式裝置作業。 |
SetHomeLedIntensity(Byte) |
在控制器的首頁按鈕中設定LED的亮度。 |
SetStandardControllerButtonRemapping(User, Boolean, IMapView<RemappingButtonCategory,Object>) |
變更用戶標準遊戲板的按鈕和軸對應。 |