Playstation 4 Controller in Adobe AIR and Flash

Posted by Zeh Fernando on 29/October/2013 at 15:37

As expected, the new PS4 controller works out-of-the-box once connected to a Windows PC (using a USB cable) with no need for any special drivers. As such, it works seamlessly when using the GameInput API in Flash or Adobe AIR applications.

I have updated the spreadsheet of known GameInput controls with the appropriate control ids. However, this is how it works, in a nutshell:

  • The device is reported as “Wireless Controller”, with 24 controls
  • The left stick X axis is reported as “AXIS_0″, going from -1 (left) to 1 (right)
  • The left stick Y axis is reported as “AXIS_1″, going from -1 (down) to 1 (up)
  • The rick stick X axis is reported as “AXIS_2″, going from -1 (left) to 1 (right)
  • The right stick Y axis is reported as “AXIS_5″, going from -1 (down) to 1 (up)
  • Directional pad up, down, left, and right are reported as “BUTTON_6″, “BUTTON_7″, “BUTTON_8″, and “BUTTON_9″, respectively, and their value is either 0 or 1
  • Square is “BUTTON_10″, with value 0 or 1
  • Cross is “BUTTON_11″, with value 0 or 1
  • Circle is “BUTTON_12″, with value 0 or 1
  • Triangle is “BUTTON_13″, with value 0 or 1
  • L1 and R1 are “BUTTON_14″ and “BUTTON_15″, respectively, with a value of 0 or 1
  • L2 is reported as either “AXIS_3″ (analog, -1 to 1) or “BUTTON_16″ (digital, 0 or 1)
  • R2 is reported as either “AXIS_4″ (analog, -1 to 1) or “BUTTON_17″ (digital, 0 or 1)
  • L3 (left stick down) is “BUTTON_20″, and R3 (right stick down) is “BUTTON_21″, with a value of 0 or 1
  • The PS button is “BUTTON_22″, with value 0 or 1
  • The Share and Options buttons are “BUTTON_18″ and “BUTTON_19″, respectively, again with a value of 0 or 1
  • Clicks on the touch pad are reported as “BUTTON_23″, with a value of 0 or 1; no way to get the touch pad position, though

After so many years of ghetto solutions, it’s great to see this gamepad finally working “natively” in Windows. Even more so knowing it can easily be used in Flash content.



5 comments posted on “Playstation 4 Controller in Adobe AIR and Flash”

Hi Zeh,

I just bought a ps4 controller and have plugged it in on my mac. It works with GameInput, though the GameInputControlName from the devnet article does not have mappings for it. I am seeing 2 things and wondered if you might see the same.

* The controller seems to disconnect for no reason and soon after using it.
* When I get the disconnect event the name and id of the device are null.

I was hoping to use this controller to avoid pushing to the console much.

Do you still recommend your KeyActionBinder class as is with air 3.9? Thanks!


Posted by Shawn on 7/November/2013 at 18:32 · Reply

    Hey Shawn,

    I wouldn’t use the GameInputControlName class at all. Adobe created that to help developers, I suppose, but because it depends on previous knowledge or the device names, it’s not bound to work with new devices until updated. I suppose that’s why most GameInput support classes by other developers (mine included) are trying to just sort of assume how things work, depending on certain strings, instead of trying to identify the input device and then present specific control names that one can use.

    I haven’t tested it long enough to see random disconnects – it worked well for the short time I tested. And I know that yes, it’s pretty frequent that “devices” come as null while transitioning from and to connected and disconnected… on my code I just ignore it and wait for another event. Haven’t seen that being a huge problem yet.

    I still very much recommend my class – that’s what I’m using in my current game prototype so I’m constantly working on it. But since I’m refactoring the way it works, it’s somewhat in transition. The new version (currently under the auto-controls trunk) should make things easier, but it doesn’t support many devices yet – I’ll build the other template/profiles once it’s finished in terms of features.

    If you want to try alternatives, though, here’s the most current ones:

    James Dean Palmer’s Gamepad
    http://blog.jdpalmer.org/2013/09/writing-portable-code-with-adobe-airs.html

    Citrus Engine’s Gamepad support classes
    http://forum.starling-framework.org/topic/gamepad-support

      Great, thanks for the quick reply! I’ll go with ignoring the dropped controls then for now. Perhaps the dropping is mac related. I’ll take a look at the options available so as not to reinvent the wheel. Thanks again!


      Posted by Shawn on 7/November/2013 at 19:07 · Reply

      When working with keyactionbinder and starling/feathers screens, is calling stop() the intended action in the dispose method on the screen? If so I may have come across a timing issue. stop() is called and runs fine, but it looks like the stop() call actually ends up happening while onKeyDown is only half way through, at line 515. Then it continues and gameInputDeviceDefinitions is now null. My screen transition is triggered by pressing the enter key. Checking gameInputDeviceDefinitions before the loop on line 522 fixes it.


      Posted by Shawn on 6/December/2013 at 18:44 · Reply


2 pingbacks posted on “Playstation 4 Controller in Adobe AIR and Flash”

[…] 4 Controller in Adobe AIR and Flash Zeh Fernando writes: As expected, the new PS4 controller works out-of-the-box once connected to a Windows PC (using a […]


Leave a comment