Homebrew Discussion SDL2 Joycon Bindings

00Cancer

Well-Known Member
OP
Newcomer
Joined
Feb 1, 2017
Messages
67
Trophies
0
Age
20
XP
103
Country
United States
SDL2 allows you use Joystick input and since SDL2 is available for the switch through devKitPro, I wanted to see if I could get the Joycons to work with it. It ended up working, but unfortunately I didn't know the bindings for the buttons, so I spent the time to check the value for each button and I came up with a list which contains all of the bindings.
Code:
A        = 0
B        = 1
X        = 2
Y        = 3
LSTICK   = 4
RSTICK   = 5
LBUMPER  = 6
RBUMPER  = 7
LTRIGGER = 8
RTRIGGER = 9
PLUS     = 10
MINUS    = 11
DPADL    = 12
DPADU    = 13
DPADR    = 14
DPADD    = 15
To setup the Joycons you first must create a Joystick in SDL and then later handle the events:
Code:
SDL_Joystick* joycon;
SDL_JoystickEventState(SDL_ENABLE);
joycon = SDL_JoystickOpen(0);
Code:
while (SDL_PollEvent(&e) != 0)
    {
        switch (e.type)
        {
        case SDL_JOYBUTTONDOWN:
            if (e.jbutton.button = <number on list>)
            {
                do whatever...
            }
            break;
        }
    }
Hope this helps anyone trying to use Joycon input with SDL
 
Last edited by 00Cancer,

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    K3Nv2 @ K3Nv2: Hawaii played it smart and said we're too hot for this land