How to add Xperia™ device support for the DUALSHOCK™3 wireless controller in your Android™ game [video]

A wide range of Xperia™ devices support the DUALSHOCK 3 wireless controller, bringing a console-like experience to PlayStation® Mobile games. You can also deliver the same functionality to Android™ games.  Read on to learn how to optimise your games for the DUALSHOCK™3 wireless controller for Android games – you’ll also find guidelines and recommendations, along with the key code mappings for the supported devices.

Develop & optimise your game for the DUALSHOCK™3 wireless controller for Android games
The DUALSHOCK 3 wireless controller provides an intuitive game play experience with gaming buttons and controls. Inputs include:

  • Left and right joysticks.
  • Directional buttons.
  • Digital buttons: triangle, circle, cross, square, L1, R1, L2, R2, Start, Select.

By adding support for the DUALSHOCK™3 wireless controller in your Android game, you’re adding a number of benefits for the end user:

  • An input experience that is more familiar to gamers.
  • Freeing up viewing space by removing onscreen controls.
  • Allowing the games to be controlled wirelessly and be displayed and played on larger screens.

If you’ve already designed your game with generic controller support, such as for a virtual game pad, it’ll be easy to add support for the DUALSHOCK™ 3 wireless controller. You just need to:

  1. Design and convert your existing game interactions to map to the DUALSHOCK™3 wireless controller, keeping in mind the tips mentioned below, and using DUALSHOCK™3 wireless controller keycode mapping table as a reference.
  2. Implement your controller design (see keycode mapping table below) and fine-tune the controls to make sure that it “feels right”, to give users the best controller experience possible.
DUALSHOCK™3 wireless controller (top view).
DUALSHOCK™3 wireless controller (top view).

Tips when adding DUALSHOCK™ 3 wireless controller support
When incorporating DUALSHOCK™3 wireless controller support into your development, you need to follow and keep the following tips in mind:

Tips to keep in mind Notes
A game should be fully playable using only touch screen controls. Most devices only have a touch screen as an input controller.
Hardware buttons should be used consistently throughout a game. Users should be allowed to configure the control settings.
In any menu, except for the main menu, the CIRCLE button should take the user back to the previous menu. In the main menu, the CIRCLE button should prompt the user with the option to exit out of the game. In North America and Europe, the CIRCLE button is used as cancel. In Asia, the CIRCLE button is used as confirm.
In any menu, the X button should be used as the confirmation button. In North America and Europe, the X button is used as confirm. In Asia, the X button is used as cancel.
On screen buttons should not appear when the user is using the DUALSHOCK™3 wireless controller. There should be an option in the options menu to turn the on screen controls off or on.

Implementing the DUALSHOCK™3 wireless controller buttons and joysticks
The DUALSHOCK™3 wireless controller support can be implemented using standard Android APIs. You’ll also need to know the key code mappings when you’re adding support for the DUALSHOCK™ 3 wireless controller in your game. Any key press on the device is described by a sequence of key events. Each key event is generally accompanied by the keycode getKeyCode() and getScanCode().

Use the table below for the keycode and scancode mappings for Xperia™ devices.

Key code mappings for all Xperia™ devices that support the DUALSHOCK™3 wireless controller.

Button Keycode Scancode
Up KEYCODE_DPAD_UP 0x124
Down KEYCODE_DPAD_DOWN 0x126
Left KEYCODE_DPAD_LEFT 0x127
Right KEYCODE_DPAD_RIGHT 0x125
Circle: ○ button KEYCODE_DPAD_BUTTON_Y 0x12d
Cross: × button KEYCODE_DPAD_BUTTON_X 0x12e
Triangle: △ button KEYCODE_DPAD_BUTTON_B 0x12c
Square: □ button KEYCODE_DPAD_BUTTON_A 0x12f
L1 KEYCODE_DPAD_L1 0x12a
R1 KEYCODE_DPAD_R1 0x12b
L2 KEYCODE_DPAD_L2 0x0128
R2 KEYCODE_DPAD_R2 0x0129
L3 KEYCODE_DPAD_THUMBL 0x0121
R3 KEYCODE_DPAD_THUMBR 0x0122
SELECT KEYCODE_DPAD_BUTTON_SELECT 0x0120
START KEYCODE_DPAD_BUTTON_START 0x0123
PS KEYCODE_DPAD_BUTTON_1 0x2d0

The following code snippet shows how buttons are detected from a DUALSHOCK™3 wireless controller.

public boolean onKeyDown(int keyCode, KeyEvent event)
{
switch(keyCode)
{
case KeyEvent.KEYCODE_DPAD_BUTTON_X:
// CROSS button pressed
break;
case KeyEvent.KEYCODE_DPAD_BUTTON_Y:
// CIRCLE button pressed
break;
...
}
return super.onKeyDown(keyCode, event);
}

The left and right analog sticks on the DUALSHOCK™3 wireless controller returns keycodes (UP, DOWN, LEFT, RIGHT for each direction) and can be used as joysticks. Each joystick has two axes (one for vertical and one for horizontal) and the range value can be obtained by calling the getMotionRange(int).  Please keep in mind joystick implementation usually takes more effort and iterations to make the control “feel right”.

For more information and references on the Android gamepad APIs, refer to the InputDevice and MotionRange topics on the Android Developer website.  You can also check out this Android and game controller video from the Android Developers for more tips on how to make your game controller compatible on Android.

How to setup the DUALSHOCK™ 3 wireless controller on your device
Currently, a number of Sony devices offer a setting that will allow you to connect a DUALSHOCK™3 wireless controller via Bluetooth™ to play games wirelessly, and the initial setup of the DUALSHOCK™3 wireless controller is quite easy.

The following Sony smartphones and tablets support the DUALSHOCK®3 wireless controller:

*DUALSHOCK®3 wireless controller can be used when the software is updated to Android 4.2.

DUALSHOCK setup

DUALSHOCK™3 wireless controller setup menu on an Xperia™ tablet.

In the settings menu of the supported devices, there is an option for “DUALSHOCK™3 wireless controller”. In addition to the DUALSHOCK™3 wireless controller and USB cable, the only other extra item you’ll need to setup your DUALSHOCK™3 wireless controller is a USB on the go adapter. Once the DUALSHOCK™3 wireless controller is connected, it can be used to navigate through menus to select, start and play games.

***

If you have any questions on how to add DUALSHOCK™3 wireless controller support in your game, feel free to leave us a comment below and we’ll get back to you with an answer as soon as we can!

PlayStation is a registered trademark of Sony Computer Entertainment Inc. SIXAXIS is a trademark of Sony Computer Entertainment Inc.

More information

Comments 181

Sort by: Newest | Oldest | Most popular

  1. By Khalid Mohamed

    #1

    I would like to know all the games that I can play with my controller in my phone

    • By Joe Padre

      #2

      Hi Khalid,
      Sorry, we don’t have an official list available. You’ll have to check if the game you’re interested in has controller support, then see if it works with your DUALSHOCK3 controller.
      Best regards,
      Joe from Developer World

  2. By Jérôme Tavel

    #3

    Hello

    I have an official Sony dualshock 3.

    The pairing with my Xperia Z2 Tablet is ok.

    The dualshock work with USB cable.

    My bluetooth work too with my Fitbit but the dualshock 3 doesn’t work in wireless.

    After the pairing with USB cable. I take off the USB cable. The 4 leds flash of the controller and nothing, no detection in wireless.

    The Dualshock 3 controller doesn’t appear in Bluetooth settings.

    Could you help me please

  3. By Luke Ellis-Snowden

    #4

    So I have an experia z3 compact and an experia tablet z the dualshock was connected worked fine and now all of the sudden it won’t even pick up the controler when I link it by wire..

  4. By Thakur Rana

    #6

    can I connect xbox wireless controller to my xperia z1

    • By Christopher Martin

      #7

      No, never. Can’t even do it with a PC without an official wireless adapter. You might be able to get a wired 360 controller to work with an OTG usb adapter but never a wireless one, cables for them only charge the controller, it has no connectivity features and the wireless controller works on a proprietary signal so there’s no hope of getting that to work.

  5. By Sameer Beg

    #8

    can controller work on xperia m2 and how to connect controller with otg cable.

  6. By Daniel Bórquez Muñoz

    #9

    Hi :) i have a DUALSHOCK™3 model CECHZC2Ua1 is a original product, support OTG in my Xperia SP but when i´m unplug the cable no recongnize wireless conection Bluetooth :( help me please, thanks!

  7. By Thisura Yapa

    #10

    Can I add the support for xperia M ??

  8. By Lyoid Jims

    #11

    Hi… Im using xperia Z3 and for some reason I can’t get it to work with Nova 3 game. I purchased Sixaxis controller and six axis enabler but I still can’t use my ps3 controller =(

  9. By Abid Pashaliciou

    #12

    Hi, I got an Xperia T3 and I’m about to buy a DS3,OTG and a Micro USB to HDMI cable, I’m not seeing my phone on the list you gave us,but in settings/connectivity there is DUALSHOCK™3 support, I hope it isn’t just there for nothing, and I’m not burying it for nothing :/ Please reply to me�

    • By Joe Padre

      #13

      Hi Abid,
      Hmm… that’s right. Xperia T3 does not show up on http://www.playstation.com/psm/certified.html. But if the setting is there on your device, then it must be supported. We’ll see if we can test it out here.
      Best regards,
      Joe from Developer World

      • By Abid Pashaliciou

        #14

        Thank you for your answer :) The phone is exact the same as the T2 Ultra only a smaller screen (5.3″)

        BTW my model number is D5103

  10. By Joel Hong

    #15

    Hello, is it possible to connect more than 1 controller to my Sony xperia z3 in order to play multiplayer games?

    • By Joe Padre

      #16

      Hey Joel,
      You can only connect 1 controller.
      Best regards,
      Joe from Developer World

  11. By Mustafa El Bizanti

    #17

    hello … i dont know why but it doesnt work when i connect my ps3 controller ? can anyone please help ??

  12. By Hicham Badr

    #20

    Hi joe,
    Thanks for answering me i really appreciate, by the way i have the android 4.4.4 and the blutooth of my dualshock 3 is ok with the tablet but it doesn’t work only inside the game. Thank u

  13. By Hicham Badr

    #21

    should i have to root my tablet z ???
    answer me please

  14. By Hicham Badr

    #22

    my dualshock 3 is connected with wirless to my tablet xperia z SGP321 and i can manipulet the android tab but when I open a game my dualshock controller can’t controlle the game (i tried all the games) !!
    what can i do ???

    • By Joe Padre

      #23

      Hi Hicham,
      According to http://www.playstation.com/psm/certified.html, for Xperia Tablet Z, a defect was found with the Bluetooth connection when using certain models of DUALSHOCK(R)3 wireless controller with Android 4.3. For details, please contact Customer Support at Sony Mobile Communications.
      Best regards,
      Joe from Developer World

Show more comments

1-23 of 181 comments. Show all comments