Share via


LegacyGipGameControllerProvider.GetStandardControllerButtonRemapping Method

Definition

Retrieves the button and axis mapping of a standard gamepad for a user.

public:
 virtual IMapView<RemappingButtonCategory, Platform::Object ^> ^ GetStandardControllerButtonRemapping(User ^ user, bool previous) = GetStandardControllerButtonRemapping;
IMapView<RemappingButtonCategory, IInspectable const&> GetStandardControllerButtonRemapping(User const& user, bool const& previous);
public IReadOnlyDictionary<RemappingButtonCategory,object> GetStandardControllerButtonRemapping(User user, bool previous);
function getStandardControllerButtonRemapping(user, previous)
Public Function GetStandardControllerButtonRemapping (user As User, previous As Boolean) As IReadOnlyDictionary(Of RemappingButtonCategory, Object)

Parameters

user
User

The user to get controller mappings for.

previous
Boolean

bool

True if the mapping should be read from the inactive Previous store; false if the active mapping should be read.

Returns

A dictionary matching each RemappingButtonCategory to data that specifies the remapping. The data type is specific to the category as follows:

RemappingButtonCategory Data Description
ButtonsSettings A uint64 composed of 16 nibbles. Each nibble represents a button's assignment. The standard assignment is 0xfedcba9876543210
AnalogSettings A uint32 with the following effects: 0x1 : Swaps triggers 0x2 : Swaps thumbsticks 0x4 : Inverts the left thumbstick 0x8 : Inverts the right thumbstick. The standard assignment is 0.
VibrationSettings A uint32 with the following effects: 0x01 : Disables vibration. The standard assignment is 0.

Examples

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);
}

Remarks

The order of the buttons for ButtonSettings from most significant to least significant is: Right Thumbstick, Left Thumbstick, Right Shoulder, Left Shoulder, DPad Right, DPad Left, DPad Down, DPad Up, Y, X, B, A, View, Menu, Guide, and Bind.

Typically, the previous parameter should be false, which will read the current controller mapping. It can also be used to read a mapping that was saved for later (for example, to read a saved mapping to restore a previous state).

Caution

Controller mapping is system-wide and persistent for the given user. This should only be done at the user's direction.

Applies to

See also