[GameControllers] Axis event is not fired

Thank you for the response =)

Like I mentioned in the opening post: I did check if the inputs were recognized by OSX with other apps. And all events are picked up. Only corona apps do not seem to pick these events up. Remember, the key events are coming through normally, but the AXIS events are not.

I will try it with a wired joystick when I get home, see if that does anything.

But that doesn’t really solve the problem though, it should also work for bluetooth connected controllers.

Again, all other apps work fine with my controllers, it’s just corona.

Isnt it possible that this is just a bug in the corona code?

@anyone using OS X,

Can anyone out there reading this who also uses OS X, please download this:

https://github.com/roaminggamer/CoronaGeek/raw/master/Hangouts/ICanMakeThat/DesktopGames/GeometryWarsClone.zip

Then, with a wired controller please play it in the simulator.

Finally, post back if it does or does not work for you.

I am not an OS X user so I can’t test this for the OP.

What other apps? Were those games or utilities? I am specifically saying don’t verify axis with games.

@roaminggamer, I’ve got good news and bad news.

Your app doesn’t work on macOS with a wired Playstation 3 controller. Both of my PS4 controllers are connected to my Playstation and I don’t want to have to break the bluetooth connection and have to set it back up.  But with my PS3 controller is wired to my USB port and bluetooth connected.

The good news, your app gets key and axis events. The bad news, is your key names are not correct for Playstation controllers. What you have are names for Xbox controllers. For the game I’ve been working on for what seems to be a couple of years, here is how I map the keys:

local controllerKeys = {} controllerKeys["Sony PLAYSTATION(R)3 Controller"] = {} controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button1"] = "select" controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button2"] = "buttonL3" controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button3"] = "buttonR3" controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button4"] = "start" controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button5"] = "up" controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button6"] = "right" controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button7"] = "down" controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button8"] = "left" controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button9"] = "buttonL2" controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button10"] = "buttonR2" controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button11"] = "buttonL1" controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button12"] = "buttonR1" controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button13"] = "buttonY" controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button14"] = "buttonB" controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button15"] = "buttonA" controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button16"] = "buttonX" controllerKeys["Sony PLAYSTATION(R)3 Controller"]["button17"] = "power" controllerKeys["Sony Computer Entertainment Wireless Controller"] = {} controllerKeys["Sony Computer Entertainment Wireless Controller"]["button1"] = "buttonX" controllerKeys["Sony Computer Entertainment Wireless Controller"]["button2"] = "buttonA" controllerKeys["Sony Computer Entertainment Wireless Controller"]["button3"] = "buttonB" controllerKeys["Sony Computer Entertainment Wireless Controller"]["button4"] = "buttonY" controllerKeys["Sony Computer Entertainment Wireless Controller"]["button5"] = "buttonL1" controllerKeys["Sony Computer Entertainment Wireless Controller"]["button6"] = "buttonR1" controllerKeys["Sony Computer Entertainment Wireless Controller"]["button7"] = "buttonL2" controllerKeys["Sony Computer Entertainment Wireless Controller"]["button8"] = "buttonR2" controllerKeys["Sony Computer Entertainment Wireless Controller"]["button9"] = "select" controllerKeys["Sony Computer Entertainment Wireless Controller"]["button10"] = "start" controllerKeys["Sony Computer Entertainment Wireless Controller"]["button11"] = "buttonL3" controllerKeys["Sony Computer Entertainment Wireless Controller"]["button12"] = "buttonR3" controllerKeys["Sony Computer Entertainment Wireless Controller"]["button13"] = "power" controllerKeys["Xbox"] = {} controllerKeys["Xbox"]["button1"] = "buttonA" controllerKeys["Xbox"]["button2"] = "buttonB" controllerKeys["Xbox"]["button3"] = "buttonX" controllerKeys["Xbox"]["button4"] = "buttonY" controllerKeys["Xbox"]["button5"] = "buttonL1" controllerKeys["Xbox"]["button6"] = "buttonR1" controllerKeys["Xbox"]["button7"] = "buttonL3" controllerKeys["Xbox"]["button8"] = "buttonR3" controllerKeys["Xbox"]["button9"] = "start" controllerKeys["Xbox"]["button10"] = "select" controllerKeys["Xbox"]["button11"] = "power" controllerKeys["Xbox"]["button12"] = "up" controllerKeys["Xbox"]["button13"] = "down" controllerKeys["Xbox"]["button14"] = "left" controllerKeys["Xbox"]["button15"] = "right"

You can see I clearly haven’t tested much with a PS4 controller since I don’t have the up/down/left/right buttons defined, but on my PS3 controller, Corona sees “button7” when I press the “down” button. For an Xbox controller, “down” is “button13”. I don’t believe macOS does any attempt at mapping hardware buttons to logical buttons.

I enabled your table.print_r() statement for the key events to verify this. I also did this for axis events but my sticks are very noisy and generates way too many events. But here is a copy/paste from my Corona console log.

Jan 14 05:58:02.689 table: 0x6000039ed200 { [normalizedValue] =\> -0.011764705181122 Jan 14 05:58:02.690 [name] =\> "axis" [device] =\> userdata: 0x60000222a518 [rawValue] =\> 126 [axis] =\> table: 0x6000039ed200 { [number] =\> 2 [type] =\> "y" [minValue] =\> 0 [maxValue] =\> 255 [accuracy] =\> 0 [descriptor] =\> "Joystick 2: Axis 2" } } table: 0x600003985000 { [normalizedValue] =\> -0.011764705181122 [name] =\> "axis" [device] =\> userdata: 0x60000222a518 [rawValue] =\> 126 [axis] =\> table: 0x600003985000 { [number] =\> 4 [type] =\> "rotationZ" [minValue] =\> 0 [maxValue] =\> 255 [accuracy] =\> 0 [descriptor] =\> "Joystick 2: Axis 4" } } Jan 14 05:58:02.714 table: 0x600003933680 { [normalizedValue] =\> -0.019607841968536 [name] =\> "axis" [device] =\> userdata: 0x60000222a518 [rawValue] =\> 125 Jan 14 05:58:02.714 [axis] =\> table: 0x600003933680 { [number] =\> 4 [type] =\> "rotationZ" [minValue] =\> 0 [maxValue] =\> 255 [accuracy] =\> 0 [descriptor] =\> "Joystick 2: Axis 4" } } Jan 14 05:58:02.748 table: 0x600003937200 { Jan 14 05:58:02.749 [normalizedValue] =\> -0.019607841968536 [name] =\> "axis" [device] =\> userdata: 0x60000222a518 [rawValue] =\> 125 [axis] =\> table: 0x600003937200 { [number] =\> 2 [type] =\> "y" [minValue] =\> 0 [maxValue] =\> 255 [accuracy] =\> 0 [descriptor] =\> "Joystick 2: Axis 2" } }

Corona is receiving the events, but I suspect it’s a mapping problem. 

The other issue, and this may be a Corona bug, is when you hide the mouse cursor, it hides it when the mouse is out of the window as long as the simulator is the foreground app.

I guess I’m going to need to sync one of these PS4 controllers after all and get my up/down/left/right buttons mapped :slight_smile:

Rob

Ah ha! I found out why I don’t have mappings for up/down/left/right with the PS4 button is I don’t get any key events for those keys on my Mac. I still don’t think this is a Corona issue, but more of a macOS issue.

Rob

Thank you so much for the response.

I am very confused though. I am not even encountering the issue with mapping, it’s just that axis events are never fired.

local function onAxisEvent(event)
print(event.axis.descriptor … ": Normalized Value = " … tostring(event.normalizedValue))
end

– Add the axis event listener
Runtime:addEventListener(“axis”, onAxisEvent)

This does nothing on osx. It works only on windows.

I tried the following setups:

ps4 wireless

ps4 wired

xbox360 wired

switch pro controller wireless

EVERYTHING for these have the exact same problems. I get the KEY events, but not the AXIS events.

I tested the controllers all with this: https://www.vpedal.com/osx-joystick-gamepad-tester/

This app shows me that all controllers SHOULD work. All buttons and joystick movements are coming in. It’s just that corona doesnt show them to me. 

I tried this all on a second macbook as well, which is a totally different model. Exact same problem. Isn’t this just a corona bug? Am I the only one with this issue?

I did a little more research on this. I can with 100% certainty that I can use PS3 controllers in Corona on macOS while wired via USB. Buttons are not mapped automatically to “up” “down” etc. But Axis items work as well. Xbox controllers work, though I have to install the Xbox 360 system preferences/driver software.

Now what is weird, with a PS4 Dual Shock controller, some buttons are recognized in Corona, but not all and neither are the Axis events. I use the Joystick Mapper software that I have installed and it can, while scanning detect axis events. So it’s possible that it’s a Corona issue for that particular controller.

You can look through the open source code for Corona at https://github.com/coronalabs/corona/tree/master/librtt/Input if you wish, but I don’t see anything device specific. I haven’t found where it binds to any macOS libraries yet.

EDIT: I found the Apple specific code: https://github.com/coronalabs/corona/tree/master/platform/apple

I still don’t see anything PS4 DualShock controller based. There are two main setups:  HID (Human Input Device) which is an industry standard and MFi (Made For iDevices).

I don’t know how HID standard a PS4 Dual Shock controller is. It’s certainly not an MFi one. But the stick information comes from the Apple GameController framework.

Rob

Thank you for doing a bit of research =)

I have no knowledge about the internals of Corona, so im not so sure what I can do to fix it now. Should I just wait for a fixed build of corona?

> Now what is weird, with a PS4 Dual Shock controller, some buttons are recognized in Corona, but not all and neither are the Axis events. I use the Joystick Mapper software that I have installed and it can, while scanning detect axis events. So it’s possible that it’s a Corona issue for that particular controller.

I have that exact same issue with all my controllers that I own. Only the 4 face buttons work (square, circle etc.). Rest is not coming through like you described.

What do you recommend me to do now?

I guess I wasn’t very clear. 

Corona does not have any controller specific code. On Apple devices, we make calls to Apple’s GameController framework. Device level operations happen inside Apple’s code. The Apple GameController framework only supports HID controllers and MFi controllers. It’s possible the PS4 Dual Shock controller isn’t fully HID compatible. It’s certainly not an MFi controller.

I can with certainty say that a PS3 controller and an Xbox 360 controller work for all buttons and axis controls while wired.

I don’t believe after doing my deeper dive into the code that this is a Corona specific issue or there is a way for us to fix this since we are dependent on what Apple’s GameController framework gives us.

Rob