Upgrade Input SDK for Java and Kotlin to version 1.1

This guide explains how to upgrade your game from the 1.0.0-beta Input SDK for Java and Kotlin to 1.1.0-beta. See the Unity upgrade guide for Unity specific instructions.

Release Notes

Google Play Games on PC supports remapping of keyboard controls based on the key bindings your game provides using the Input SDK.

Users access this feature by opening the overlay, selecting controls, and then clicking on the action they wish to remap.

Google Play Games on PC maps every user-remapped input onto your game's default input. This way your game doesn't have to be aware of the player's remapping. If you need to know the new input for an in-game action, such as displaying the keyboard controls in your game, you may optionally register a callback to be notified for remapping events.

Google Play Games on PC stores each user's remapped controls locally so they are persistent across gaming sessions. Since this is stored locally, it does not influence the mobile experience and is deleted upon uninstallation of Google Play Games on PC. Control settings are not persisted across multiple PC devices.

You don't need to upgrade the Input SDK to enable key remapping in your game, but remapping can be disabled for your game if an unsupported configuration is detected.

If you want to control the input remapping experience, or if the remapping feature is disabled for your game, perform the following steps to resolve:

  • Upgrade to Input SDK 1.1.0-beta.
  • Update any keybindings to avoid the unsupported configurations.
  • Update your InputMap to set the remapping feature enabled.

If you want to opt-out of the remapping feature for your game while still displaying the read-only version of your key bindings, follow these steps:

  • Upgrade to Input SDK 1.1.0-beta.
  • Update your InputMap to set the remapping feature to disabled.

You can upgrade your version of the Input SDK to 1.1.0-beta to take advantage of advanced remapping features in Google Play Games on PC by using InputContexts to define controls for different scenes of your game, add callbacks to listen for remapping events, define a set of reserved keys that the user cannot remap to, and deactivate the remapping feature per InputAction, InputGroup or InputMap.

Consider the following exceptions while upgrading to the new SDK version:

Unsupported configurations

Input remapping is disabled if the following conditions are not met:

  • An InputAction utilizing multiple keys must be composed of a modifier and non-modifier key. For example, Shift + A is valid but A + B, Ctrl + Alt, and Shift + A + Tab are not.

  • Two or more InputAction or InputGroup objects cannot share the same unique ID.

Upgrade

Input SDK 1.1.0-beta is backward compatible with Input SDK 1.0.0-beta. Games using previous implementations of the Input SDK still support basic remapping, unless they use an unsupported configuration. If your game is using an earlier version of the Input SDK, consider reading the upgrade guide from 0.0.4 to 1.0.0-beta.

Upgrading to 1.1.0-beta enables new features including:

Upgrade dependency

If you are using Gradle to import the Input SDK, upgrade to the newest version:

// build.gradle
dependencies {
   ...
   implementation 'com.google.android.libraries.play.games:inputmapping:1.1.0-beta'
   ...
}

Define static fields

For version 1.1.0-beta it is a good practice to define your InputAction, InputGroup, InputContext and InputMap objects as static fields of your InputMappingProvider class since these fields are accessible from other parts of your application:

Kotlin

class InputSDKProvider : InputMappingProvider {
    override fun onProvideInputMap(): InputMap { return gameInputMap }

    companion object {
        const val INPUTMAP_VERSION = "1.0.0"

        private val moveUpInputAction = InputAction.create(...)
        private val movementInputGroup = InputGroup.create(...)
        val menuContext = InputContext.create(...)
        val gameInputMap = InputMap.create(...)
    }
}

Java

public class MyInputMappingProvider implements InputMappingProvider {
    private static final String INPUTMAP_VERSION = "1.0.0";

    private static final InputAction moveUpInputAction =
        InputAction.create(...);
    private static final InputGroup movementInputGroup = InputGroup.create(...);
    public static final InputContext menuContext = InputContext.create(...);
    public static final InputMap gameInputMap = InputMap.create(...);

    @Override
    public InputMap onProvideInputMap() {
        return gameInputMap;
    }
}

Update your InputActions

The InputAction.create() method of Input SDK 1.0.0-beta is deprecated. An InputAction now has a version identifier and can be marked as remappable or not. An InputAction defined using the Input SDK 1.0.0-beta create() method is remappable by default and lacks versioning information:

InputAction in Input SDK 1.0.0-beta

Kotlin

val jumpInputAction = InputAction.create(
    "Jump",
    InputEventIds.JUMP.id,
    InputControls.create(
        listOf(KeyEvent.KEYCODE_SPACE),
        emptyList()
    )
)

Java

InputAction moveUpInputAction = InputAction.create(
    "Move Up",
    InputEventIds.MOVE_UP.ordinal(),
    InputControls.create(
        Collections.singletonList(KeyEvent.KEYCODE_W),
        Collections.emptyList()
    )
);

InputAction in Input SDK 1.1.0-beta

Kotlin

companion object {
  private val moveUpInputAction = InputAction.create(
    "Move Up",
    InputActionsIds.DRIVE.ordinal.toLong(),
    InputControls.create(listOf(KeyEvent.KEYCODE_W), emptyList()),
    InputEnums.REMAP_OPTION_ENABLED) // This action is remappable
}

Java

private static final InputAction moveUpInputAction = InputAction.create(
    "Move Up",
    InputEventIds.MOVE_UP.ordinal(),
    InputControls.create(
            Collections.singletonList(KeyEvent.KEYCODE_W),
            Collections.emptyList()),
    InputEnums.REMAP_OPTION_ENABLED // this action is remappable
);

InputAction in Input SDK 1.1.0-beta (with version string)

Kotlin

private val enterMenuInputAction = InputAction.create(
    "Enter menu",
    InputControls.create(listOf(KeyEvent.KEYCODE_ENTER), emptyList()),
    InputIdentifier.create(
    INPUTMAP_VERSION, InputActionsIds.ENTER_MENU.ordinal.toLong()),
    InputEnums.REMAP_OPTION_ENABLED
)

Java

private static final InputAction moveUpInputAction = InputAction.create(
    "Move Up",
    InputControls.create(
            Collections.singletonList(KeyEvent.KEYCODE_W),
            Collections.emptyList()),
    InputIdentifier.create(
            INPUTMAP_VERSION,
            InputEventIds.MOVE_UP.ordinal()),
    InputEnums.REMAP_OPTION_ENABLED // this action is remappable
);

For more information about versioning your key bindings, see Tracking key IDs.

Update your InputGroups

In Input SDK 1.1.0-beta you need to uniquely identify each InputGroup. Each InputAction belongs to an InputGroup -- a collection of related actions. This improves navigation and discoverability of the controls during gameplay. In the same way that InputAction must have a unique identifier among all the actions in a single InputContext, an InputGroup must have a unique ID across the existing groups.

For the examples in this section, a game has two InputContext objects representing the main menu and gameplay. Appropriate IDs are tracked for each InputGroup in these contexts using the following enumeration:

Kotlin

enum class InputGroupsIds {
    // Main menu scene
    BASIC_NAVIGATION, // WASD, Enter, Backspace
    MENU_ACTIONS, // C: chat, Space: quick game, S: store
    // Gameplay scene
    BASIC_MOVEMENT, // WASD, space: jump, Shift: run
    MOUSE_ACTIONS, // Left click: shoot, Right click: aim
    EMOJIS, // Emojis with keys 1,2,3,4 and 5
    GAME_ACTIONS, // M: map, P: pause, R: reload
}

Java

public enum InputGroupsIds {
    // Main menu scene
    BASIC_NAVIGATION, // WASD, Enter, Backspace
    MENU_ACTIONS, // C: chat, Space: quick game, S: store
    // Gameplay scene
    BASIC_MOVEMENT, // WASD, space: jump, Shift: run
    MOUSE_ACTIONS, // Left click: shoot, Right click: aim
    EMOJIS, // Emojis with keys 1,2,3,4 and 5
    GAME_ACTIONS, // M: map, P: pause, R: reload
}

Like InputAction, the InputGroup.create() method of the Input SDK 1.0.0-beta has been deprecated. You must update your InputGroup in your game with a version identifier and boolean indicating whether the InputAction objects in your groups are remappable. Groups created with the deprecated Input SDK 1.0.0-beta create() method are remappable, have the ID 0, and the version ID is an empty string (""):

InputGroup in Input SDK 1.0.0-beta

Kotlin

val movementInputGroup = InputGroup.create(
    "Basic Movement",
    listOf(
        moveUpInputAction,
        moveLeftInputAction,
        moveDownInputAction,
        moveRightInputAction,
        jumpInputAction,
        runInputAction)
)

Java

InputGroup movementInputGroup = InputGroup.create(
    "Basic movement",
    Arrays.asList(
        moveUpInputAction,
        moveLeftInputAction,
        moveDownInputAction,
        moveRightInputAction,
        jumpInputAction,
        runInputAction
    )
);

InputGroup in Input SDK 1.1.0-beta

Kotlin

companion object {
    private val movementInputGroup = InputGroup.create(
        "Basic movement",
        listOf(
            moveUpInputAction,
            moveLeftInputAction,
            moveDownInputAction,
            moveRightInputAction,
            jumpInputAction,
            runInputAction),
        InputGroupsIds.BASIC_MOVEMENT.ordinal.toLong(),
        // All the actions in this groups can't be remapped
        InputEnums.REMAP_OPTION_DISABLED
    )
}

Java

private static final InputGroup movementInputGroup = InputGroup.create(
    "Basic movement",
    Arrays.asList(
            moveUpInputAction,
            moveLeftInputAction,
            moveDownInputAction,
            moveRightInputAction,
            jumpInputAction,
            runInputAction
    ),
    InputGroupsIds.BASIC_MOVEMENT.ordinal(),
    // All the actions in this groups can't be remapped
    InputEnums.REMAP_OPTION_DISABLED
);

InputGroup in Input SDK 1.1.0-beta (with version string)

Kotlin

companion object {
    private val movementInputGroup  = InputGroup.create(
        "Basic movement",
        listOf(
            moveUpInputAction,
            moveLeftInputAction,
            moveDownInputAction,
            moveRightInputAction,
            jumpInputAction,
            runInputAction),
        InputIdentifier.create(
            INPUTMAP_VERSION, InputGroupsIds.BASIC_MOVEMENT.ordinal.toLong()),
        // All the actions in this groups can't be remapped
        InputEnums.REMAP_OPTION_DISABLED
    )
}

Java

private static final InputGroup movementInputGroup = InputGroup.create(
    "Basic movement",
    Arrays.asList(
            moveUpInputAction,
            moveLeftInputAction,
            moveDownInputAction,
            moveRightInputAction,
            jumpInputAction,
            runInputAction
    ),
    InputIdentifier.create(
            INPUTMAP_VERSION,
            InputGroupsIds.BASIC_MOVEMENT.ordinal()),
    // All the actions in this groups can't be remapped
    InputEnums.REMAP_OPTION_DISABLED
);

For more information about versioning your key bindings, see Tracking key IDs.

Update your InputMap

InputMap.create() method of Input SDK 1.0.0-beta is deprecated. Update your InputMap to assign a version identifier, opt out completely from the remapping feature or assign a list of reserved keys for your game that you don’t want to be used for remapping by the user. Every InputMap defined using the Input SDK 1.0.0-beta create() method is remappable by default, is identified with the ID 0, and doesn’t have any reserved keys.

InputMap in Input SDK 1.0.0-beta

Kotlin

val gameInputMap = InputMap.create(
    listOf(movementInputGroup, mouseMovementInputGroup),
    MouseSettings.create(true, false)
)

Java

InputMap gameInputMap = InputMap.create(
    Arrays.asList(movementInputGroup, mouseMovementInputGroup),
    MouseSettings.create(true, false)
);

InputMap in Input SDK 1.1.0-beta

Kotlin

companion object {

  const val INPUTMAP_VERSION = "1.0.0"
  const val INPUT_MAP_ID = 0

  val gameInputMap = InputMap.create(
    listOf(movementInputGroup, mouseMovementInputGroup),
    MouseSettings.create(true, false),
    InputIdentifier.create(INPUTMAP_VERSION, INPUT_MAP_ID.toLong()),
    InputEnums.REMAP_OPTION_ENABLED,
    // Use ESCAPE as reserved key
    listof(InputControls.create(listOf(KeyEvent.KEYCODE_ESCAPE), emptyList()))
  )
}

Java


public static final String INPUT_MAP_VERSION = "1.0.0-beta";
public static final long INPUT_MAP_ID = 0;

public static final InputMap gameInputMap = InputMap.create(
        Arrays.asList(movementInputGroup, mouseMovementInputGroup),
        MouseSettings.create(true, false),
        InputIdentifier.create(INPUTMAP_VERSION, INPUT_MAP_ID),
        InputEnums.REMAP_OPTION_ENABLED,
        // Use ESC key as reserved key
        Arrays.asList(
                InputControls.create(
                        Collections.singletonList(KeyEvent.KEYCODE_ESCAPE),
                        Collections.emptyList()
                )
        )
);

What's next

Continue your upgrade to 1.1.0-beta by Assigning different controls for different scenes using InputContexts or updating the UI of your game by Getting notified on remapping events using InputRemappingListeners.

When updating your key-bindings take a look at the Best practices for designing your key bindings and consider the restrictions and limitations of the remapping feature.