View Full Version : How do I map buttons for SDL
3DModelerMan
10-21-2008, 07:34 AM
I have a logitech dual action gamepad, that I want to use SDL for input, I have code like in the doc wiki tutorial on SDL but I don't get any input registered by my program I can post code later.
Thanks:happy: .
monjardin
10-21-2008, 09:23 AM
Did you open the joystick (http://libsdl.org/cgi/docwiki.cgi/SDL_JoystickOpen) and enable joystick events (http://libsdl.org/cgi/docwiki.cgi/SDL_JoystickEventState)?
3DModelerMan
10-21-2008, 10:49 AM
I open it like this
//{player 1 joystick
SDL_Joystick *joystick1;
SDL_JoystickEventState(SDL_ENABLE);
if(SDL_NumJoysticks()>0) joystick1 = SDL_JoystickOpen(0);
//}
and I trie to access it like this
//{SDL event receiver
switch( event.type )
{
//{keyboard events
case SDL_KEYDOWN:
/* handle keyboard stuff here */
break;
//}
//{joystick events
case SDL_JOYHATMOTION: // Handle Hat Motion
if ( event.jhat.value && SDL_HAT_UP )
{
menu_item ++;
}
if ( event.jhat.value && SDL_HAT_DOWN )
{
menu_item --;
}
break;
//}
}
//}
//}
I did'nt do anything to my gamepad, just plugged it in out of the box.
By trying to access the joystick "hat" I'm accessing the "D pad" right?.
Reedbeta
10-21-2008, 11:01 AM
Just a note, please use ... when posting code on the forum. Thanks!
3DModelerMan
10-21-2008, 11:05 AM
Oh sorry, I did'nt see that option. But do I need to use the logitech profiler
to map anything, I know that I open the gamepad, I tested putting analog control instead of D pad but it still does'nt do it.
monjardin
10-22-2008, 08:27 PM
Did you initialize the joystick sub-system (i.e. bitwise-or SDL_INIT_JOYSTICK with your other parameters in the SDL_Init call)? Also, I'm not sure if your gamepad acts as a HAT switch. Have you tried any buttons?
3DModelerMan
10-23-2008, 07:53 AM
I tried the analog to.
//initialize SDL
if(SDL_Init(SDL_INIT_JOYSTICK|SDL_INIT_TIMER) < 0) return 1;
that's how I init SDL. I use irrlicht with would this conflict?.
monjardin
10-27-2008, 08:32 PM
What operating system are you using? If it is Windows, does the joystick show up as a human interface device (HID)?
Do you check the value of joystick1 to make sure it is not NULL or unassigned? Your code snippet does not show proper handling of not detecting any joysticks.
3DModelerMan
10-28-2008, 07:39 AM
Not showing up as NULL, and it shows up fine in the game controllers section of the Windows XP control pad.
monjardin
10-28-2008, 08:00 PM
I believe I recall the Dual Action having a button that changes the behavior of the D-pad. I believe it shows up as a pair of axes in one configuration, but I don't know if it works as a HAT switch or not. Are you sure you are not getting any button events? Also, are you pumping the SDL message loop properly?
Have you gotten keyboard events to work first? Here is a simple tutorial. (http://gpwiki.org/index.php/C:SDL_Keyboard_Input_using_an_Event_Loop)
3DModelerMan
10-29-2008, 07:54 AM
Okay I'll read that tutorial and trie to get it working, I use Irrlicht though so could it be swallowing up events?.
3DModelerMan
10-29-2008, 08:17 AM
YAAAAAAAAAAAAAAAAAY!!!!!!!!! I got it working the device was swallowing up events just init the SDL before Irrlicht and it works!.
Thanks guy!:yes: .
monjardin
10-31-2008, 06:52 AM
Irrlicht was swallowing the events? That's good to know for future reference. I'm glad you got it working!
vBulletin, Copyright ©2000-2010, Jelsoft Enterprises Ltd.