Author Topic: How to configure the joypad?  (Read 4287 times)

0 Members and 1 Guest are viewing this topic.

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
How to configure the joypad?
« on: August 21, 2015, 11:43:36 PM »
Hi! I am using a joypad of microsoft (of the Xbox360). I would like to set a default configuration like this:
A = "attack", B = "action", X = "item_1", Y = "item_2", Start = "pause", Analog-stick = directions.

The start button and the analog stick work by default as I want. What should I do to set the behaviour of the other keys to call the corresponding commands? Is there already some example to do this? (I would like to associate the buttons of the joypad to the commands, avoiding to define a casewise function on_key_pressed(key), if possible.)

I have read the Lua API but I did not find a short way to do it. Also, I don't know which "keys" are the ones associated to the buttons A,B,X,Y. Could you help me?  :-\
« Last Edit: August 22, 2015, 02:08:38 AM by Diarandor »
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
Re: How to configure the joypad?
« Reply #1 on: August 22, 2015, 10:55:46 AM »
There is no way to programmatically know joypad button names as the user sees them ("A", "Start", and others). What SDL gives us is only "button 1", "button 2", etc. I believe this is the same with other frameworks than SDL.

So you need a menu to let the user configure commands. game:capture_command_binding is handy to do that. See the one of zsdx for example.

Diarandor

  • Hero Member
  • *****
  • Posts: 1062
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: How to configure the joypad?
« Reply #2 on: August 22, 2015, 02:24:57 PM »
Thanks a lot! It worked. Currently, I am using just:
Code: [Select]
-- Configure some joypad buttons.
game:set_command_joypad_binding("action", "button 10")
game:set_command_joypad_binding("attack", "button 11")
game:set_command_joypad_binding("item_1", "button 12")
game:set_command_joypad_binding("item_2", "button 13")
Although, as you say, the number of the keys will be different for other joypads. (But maybe this works for all microsoft joypads.)
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

Shade Aurion

  • Newbie
  • *
  • Posts: 26
  • DudeGoBack
    • View Profile
    • DudeGoBack
Re: How to configure the joypad?
« Reply #3 on: February 09, 2018, 07:46:14 AM »
Sorry for the necropost

I would also like to do this? Does this require a .lua file in a specific folder or altering an existing .lua file?