Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

[GameControllers] Axis event is not fired
Started by mail8527 Jan 12 2019 01:25 PM

* * * * * 1 votes
14 replies to this topic
controllers axis event
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

mail8527

[GLOBAL: userInfoPane.html]
mail8527
  • Observer

  • 13 posts
  • Corona SDK

Hey!

 

I am working with game controllers at the moment, and I have no issue getting the 'key' events for my controllers (which only work for face buttons btw, no other button besides circle/square/triangle/X or A/B/Y/X (on switch pro controller).

 

However, I never get any events in when I listen to the Axis events. I did a double check if my mac does get the axis events with another program, and that does indeed show changes when I rotate the sticks and whatnot.

 

I copied the exact examples for the corona api documentation.

 

What could be the problem? Am I missing some kind of config maybe?

 

Edit:

Just checked out this sample app: https://github.com/coronalabs/samples-coronasdk/tree/master/Hardware/InputDevices

Same problem, nothing is being picked up if I do stuff on my controller

 

edit2:

just checked it with another (older) macbook, exact same problem occurs



[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,492 posts
  • Corona SDK

What device are you simulating?

 

Are you running Corona on a OS X or Win machine?

 

What exact controller are you using and is it attached via USB?



[TOPIC: post.html]
#3

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,492 posts
  • Corona SDK

Note: That sample uses the DPAD, not the sticks on your controller.

 

It works for me on Windows simulating any device using a Logitech Gamepad F310

Of course, only the DPAD inputs do anything.



[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,492 posts
  • Corona SDK

I have a ton of examples here:

https://github.com/roaminggamer/RG_FreeStuff

 

and here:

https://github.com/roaminggamer/CoronaGeek

 

You may find these especially interesting: 

https://github.com/roaminggamer/CoronaGeek/tree/master/Hangouts/ICanMakeThat

 

Please download this and try it:

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



[TOPIC: post.html]
#5

mail8527

[GLOBAL: userInfoPane.html]
mail8527
  • Observer

  • 13 posts
  • Corona SDK

Just tested it on Windows too. There everything works fine. Seems that there are problem with corona for OSX only.

I tried many different devices, all have the same problem (on OSX):

the axis event is never fired from there.

 

I am using a ps4 pro controller and a switch pro controller. All via bluetooth.

None of any example work for me on OSX, only on windows



[TOPIC: post.html]
#6

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,492 posts
  • Corona SDK

Are you sure it isn't just an OS X problem?

 

You should really be using a  wired USB joystick for best compatibility. 

 

Have you tested your gamepad with a non-game program?  There are plenty of utility apps out there for testing joysticks and gamepads.  

 

There are also plenty of 'router helpers' out there to help get the inputs to other apps.

 

I suspect that OS X is not routing the events to Corona.  Corona cannot control this.

 

I seem to recall that OS X wasn't always great with joysticks and gamepads (in general).

 

Tip: The gamepad I use is only $20 nowadays:

 

https://www.amazon.com/Logitech-940-000110-Gamepad-F310/dp/B003VAHYQY/ref=sr_1_1?ie=UTF8&qid=1547407468&sr=8-1&keywords=logitech+f310



[TOPIC: post.html]
#7

mail8527

[GLOBAL: userInfoPane.html]
mail8527
  • Observer

  • 13 posts
  • Corona SDK

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?



[TOPIC: post.html]
#8

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,492 posts
  • Corona SDK

@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.

[TOPIC: post.html]
#9

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,492 posts
  • Corona SDK

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.


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

[TOPIC: post.html]
#10

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,372 posts
  • Enterprise

@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 :-)

 

Rob



[TOPIC: post.html]
#11

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,372 posts
  • Enterprise

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



[TOPIC: post.html]
#12

mail8527

[GLOBAL: userInfoPane.html]
mail8527
  • Observer

  • 13 posts
  • Corona SDK

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?



[TOPIC: post.html]
#13

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,372 posts
  • Enterprise

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



[TOPIC: post.html]
#14

mail8527

[GLOBAL: userInfoPane.html]
mail8527
  • Observer

  • 13 posts
  • Corona SDK

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?



[TOPIC: post.html]
#15

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,372 posts
  • Enterprise

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




[topic_controls]
[/topic_controls]