top

Gamepad

This document covers how to use gamepad with Gamepad API.

Overview

This is gamepad sample image.

Figure 1. Gamepad

Figure 1. Gamepad

Basic gamepad has 4 axes and up to 17 buttons. Other gamepads may have different styles and layouts of axes and buttons.

There are some constraints for using gamepad on Samsung TV.

  • Vibration is not supported.

  • Gamepad is not supported on SDK.

  • Maximum 2 gamepads are supported.

  • Gamepad becomes available after user presses any button or moves any axis.

Dependencies

Depending on the model of Samsung TV, gamepad can be supported or not. Please refer to the following table.

Table 1. Support Model
Product Support Model
Samsung TV All of 2016 Samsung TV models onwards

Calling Gamepad API

To receive event when clicking key of Gamepad, you can use Gamepad API. Currently supported Gamepad API version is working draft 29 May 2012. Because it is web standard, you can get more information on Gamepad API.

  • webkitgamepadconnected event is fired when gamepad has been connected.
    The parameter of callback function provides access to associated gamepad data.
  • webkitgamepaddisconnected event is fired when gamepad is disconnected.
    In callback function, you should set gamepad variable as undefined for removing gamepad value.
var gamepad;

window.addEventListener('webkitgamepadconnected', function(event) {
	gamepad = event.gamepad;
	console.log('event.gamepad : ' + JSON.stringify(event.gamepad));
});

window.addEventListener('webkitgamepaddisconnected', function() {
	gamepad = undefined;
});

The following table is information of gamepad interface.

Table 2. Information of gamepad interface
Variable Type Description Range
id string Identification string for the gamepad.
index long The index of gamepad. 0 ~
timestamp DOMTimeStamp Last time the data for this gamepad was updated.
axes float[] Array of values for all axes of the gamepad. [-1.0 … 1.0]
buttons float[] Array of values for all buttons of the gamepad. [0.0 … 1.0]

You can receive value of gamepad. Please refer to the following.

console.log(gamepad.axes[0]); // axes[0]
console.log(gamepad.buttons[0]); // buttons[0]

Checking Specific Gamepad Connection Status

If you want to check whether specific gamepad is connected or not, when application is launched, you can add meta data on “config.xml”. Please refer to the following.

 <tizen:metadata key='http://samsung.com/tv/metadata/gamepad' value='xxx'></tizen:metadata>

The value is model name of gamepad. For example,

  • dualshock4

  • usbgamepad::xxx (Two models)

  • xxx::yyy::zzz (Three models)

For example, when application is launched, if dualshock4 gamepad is not connected, the following popup is shown. Please refer to the following.

Figure 2. Connection Status

Figure 2. Connection Status

Sample Application