3

On a whim I bought a Sony DualShock 4 Wireless game controller. Pairing the controller with my mac was easy. The controller works as expected in OpenEmu.

Now I want to use the controller in my own game. In an XCode playground, I tried this:

import Cocoa;
import GameController;

print(GCController.controllers())
print(GCController.controllers().count)

The output is: [] 0

This means that the DualShock controller wasn't registered as a GCController.

Should it?

Is there some kind of initialization that needs to be done before invoking controllers?

An example is Objective-C or Swift would be welcome.

soegaard
  • 30,661
  • 4
  • 57
  • 106
  • Did you ever figure this out? – sak Jun 21 '16 at 11:02
  • Yes and no. The DualShock 4-controller is not supported by Apple's framework. I have some code here with references to more information. The general structure of the code seems okay - but I think there were a bug - somewhere... https://github.com/soegaard/dualshock4/blob/master/dualshock4.rkt – soegaard Jun 21 '16 at 14:12

2 Answers2

2

There's a tutorial here: http://www.raywenderlich.com/forums/viewtopic.php?f=21&t=10339 but that seems to suggest that the DualShock 4 isn't supported by the GameController framework.

See the Apple documentation, I would begin here: https://developer.apple.com/library/mac/documentation/ServicesDiscovery/Conceptual/GameControllerPG/DiscoveringControllers/DiscoveringControllers.html which explains how to discover and connect to controllers.

InsertWittyName
  • 3,930
  • 1
  • 22
  • 27
  • Thanks for the links. The comments to Ray Wenderlich's blog post suggests the problem is that the DualShock 4 controller is supported by the GameController framework. The documentation says to call the class method `controllers` which is what I did in the example. The other methods is as far as I can tell, meant to be used to get information about controllers being added or removed later on. – soegaard Mar 28 '15 at 19:21
  • "is supported" -> "is not supported" – soegaard Jun 21 '16 at 14:13
1

It looks as though DualShock 4 support was added to the Game Controller framework in 2019. This is working for me on macOS 11.1.

However, it looks as though the controller doesn't show up in the initial call to GCController.controllers(). You need to register for GCControllerDidConnect notifications and then the controller will show up (for both USB and Bluetooth connections).

writhe
  • 86
  • 1
  • 2