Sign in to follow this  
sirGustav

[SDL] More than 3 buttons on the mouse?

Recommended Posts

sirGustav    588
Sorry if this has been posted before. If it has please post the url cause I couldn't find any relevant information that is related to my problem. Problem: I cant find any documentation on how to detect input from other than the defined mouse-buttons(left, right, middle). I've tried to detect the mouse4 button but with no success. It seems that I dont even get an event when I press #4. While this is really not that big suprise(it isn't in the api or the doc) I was wondering on how to fix it, or work around it. Any tips? I'm using sdl 1.2 on windows if that matters. The mouse I'm testing with: Logitech Mouseman Dual Optical

Share this post


Link to post
Share on other sites
carlosadc    132
Well what you can do is to write a simple program to print out the index of every button you press on your mouse. SDL_BUTTON_LEFT, SDL_BUTTON_MIDDLE, SDL_BUTTON_RIGHT, this are just constants to make your coding easier but what "button" index really means in the SDL_MouseButtonEvent structure is a number between 1 and 255 where all your mouse buttons are stored, that way you can see that SDL_BUTTON_LEFT really means 1, and so on. So give it a try and let me know if it worked! :)

Share this post


Link to post
Share on other sites
nullsquared    126
Quote:
Original post by carlosadc
Well what you can do is to write a simple program to print out the index of every button you press on your mouse. SDL_BUTTON_LEFT, SDL_BUTTON_MIDDLE, SDL_BUTTON_RIGHT, this are just constants to make your coding easier but what "button" index really means in the SDL_MouseButtonEvent structure is a number between 1 and 255 where all your mouse buttons are stored, that way you can see that SDL_BUTTON_LEFT really means 1, and so on. So give it a try and let me know if it worked! :)


I've tried it - it does not register any other button* other than the left, right, and middle one. Infact, it does not register my side buttons as events at all.

I guess it's just a little problem with SDL. We'll have to wait to see if later versions fix it (it might also be a platform issue - I don't know).

*It also seems to recognize mouse wheel up as 4 and mouse wheel down as 5.

Share this post


Link to post
Share on other sites
sirGustav    588
I guess I should have posted here when I solved it...
Note: thoose extra buttons are called x1 and x2 in the windows API so that's what I've named them, don't have a exact name for them(It may be x buttons but I am unsure).

SDL in windows(can't say for other OS's as I'm primary a windows guy) doesn't recognize theese events, since they are technicly neither mouse nor keyboard events. Because of this, modifications to SDL is needed.

Below is my old midification-notes for the fix(windows only) - I have changed and recompiled the original source, the lines refers to the 1.2.9 release.
The docs stated that this would only work in windowed mode, however according to my tests it works in fullscreen aswell.

The event spy tool that comes with visual studio 2003 (I think) helped me alot as it helped me name the buttons and gave me something to google on and to search for in the API's.

As far as I can tell it works when I compiled it with visual studi 2003, haven't tried with my current enviroment(mingw) yet and I will try it with the EE when I move over to it in a few weeks.

As I don't own a double-x mouse I can't test it to see if it sends the correct events if I use a double-x mouse, but this seems to work with one-x mice.

I will submit the modifications(long before x-mas, around october I hope) after I tested it with a double-x mice and also compiled it with mingw and EE, until then this will hopefully help thoose in the same seat as me :)

/****************************************************/
/****************************************************/
/****************************************************/
/** In SDL_sysevents.c */
/****************************************************/
/****************************************************/
/****************************************************/

///////////// CODE ///////////////

#ifdef _WIN32_WCE
#define NO_GETKEYBOARDSTATE
#define NO_CHANGEDISPLAYSETTINGS
#endif

// this is line 53

/** SG added */
#ifndef WM_XBUTTONDOWN // For Win2K / winME ONLY
# define WM_XBUTTONDOWN 0x020B
# define WM_XBUTTONUP 0x020C
# define WM_XBUTTONDBLCLK 0x020D
#endif
#define MK_XBUTTON2 40 // forward?
#define MK_XBUTTON1 20 // backward?

/* The window we use for everything... */

//////////// CODE //////////////////////////////


// line 306
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MBUTTONDOWN:
case WM_MBUTTONUP:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
// SG added
case WM_XBUTTONDOWN:
case WM_XBUTTONUP:{
int ret = 0; // SG added since xevent should return 1, all others 0 (that's why we default to 0)
/* Mouse is handled by DirectInput when fullscreen */

////////////// CODE ////////////////////////////
// the next line is #351
case WM_RBUTTONUP:
button = SDL_BUTTON_RIGHT;
state = SDL_RELEASED;
break;
/* SG added*/
case WM_XBUTTONUP:
button = (HIWORD(wParam)==MK_XBUTTON1) ? (SDL_BUTTON_X1) : (SDL_BUTTON_X2);
state = SDL_RELEASED;
ret = 1;
break;
case WM_XBUTTONDOWN:
button = (HIWORD(wParam)==MK_XBUTTON1) ? (SDL_BUTTON_X1) : (SDL_BUTTON_X2);
state = SDL_PRESSED;
ret = 1;
break;
default:
/* Eh? Unknown button? */
return(0);
}

//////////// CODE /////////////////////////////

// again, the next line is 390
posted = SDL_PrivateMouseButton(
state, button, x, y);
}
return ret; // SG added
}
return(0);


/****************************************************/
/****************************************************/
/****************************************************/
/** In SDL_mouse.h */
/****************************************************/
/****************************************************/
/****************************************************/

////////// CODE /////////////////////

// the following line is #128
#define SDL_BUTTON_WHEELDOWN 5
#define SDL_BUTTON_X1 6
#define SDL_BUTTON_X2 7
#define SDL_BUTTON_LMASK SDL_BUTTON(SDL_BUTTON_LEFT)

///////// CODE ////////////////////////

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this