🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

strange glitch with mouse input and SDL (mouse button stuck down?)

Started by
3 comments, last by PnP Bios 19 years, 10 months ago
hi, ive recently came across a strange glitch in my input system. its for my map editor thats made w / SDL and OpenGL. anyway, for some reason, at some point, the mouse gets screwed up, and its as if the mouse button is stuck down... IE, i can just hover over a button and it will auto-click it for me, like as if my left mouse button is stuck down. its pretty weird. i noticed i could stop the glitch by left clicking somewhere in the screen. i also think im not able to grab and drag the window while this is happening. if anyone has experianced something like this before and can help, it would be appreciated. do you think this bug could be because i have unicode enabled maybe? thanks for any help
FTA, my 2D futuristic action MMORPG
Advertisement
its been awhile since i last programmed sdl but could this be happening if you had your editor loose focus during a mouse press?

iirc sdl does not generate mouseup events if your cursor leaves the window so maybe you need to check for events which tell you about this sort of stuff

but i could be far off the solution, its just an idea :)
http://mitglied.lycos.de/lousyphreak/
Yes, as LousyPhreak mentioned, the problem could be the result of moving out of the window and releasing the mouse button. Are you using windowed mode?

If not, I imagine there must be a flaw in your mouse handling routines... are you certain that you are processing the mouseup event in all cases?

If possible, why not post some code?


Ryan
--Visit the Game Programming Wiki!
hi guys,

thanks a lot for your replies! yes, i AM in windowed mode. theres one thing i should mention though, i do NOT check for mouse input in my input polling loop. instead, i grab the mouse info directly. it looks like this:

	if(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))	{               do stuff()        }


that checks if the left mouse button is clicked. i can get the mouse wheel click and the rightm ouse button by putting 2 and 3 in replace of 1 in the above code.

also, i tried clicking then moving out of the window, but that did not re-produce the bug.

one thing i should note, is that in a lot of cases, i do a trick to not allow multiple inputs really fast over the course of a few frames. the problem is, i would click a button, then immediately after clicking this button, the if() statement (above) would execute again, even though i only clicked once. im guessing because over the course of several frames, the if() statement holds true, since im getting 30 FPS and clicking the button over the course or 1/10 of a second.

anyway, heres the trick i do:

         static bool lmbpressed = false;	if(SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1))	{		if (!lmbpressed)  	        {                   DO STUFF HERE!!!!                }							lmbpressed = true;		}	else lmbpressed = false;


this makes it so that one click really only means one click, even if i click and hold for 10 seconds, it will only execute one time. do you think maybe this could be causing it somewhere? i dont share the same static boolean in any 2 checks though, at least i dont think. thanks for any help.
FTA, my 2D futuristic action MMORPG
I don't know if this would help, but my mouse input tutorial has an attached source file, it may help to look through the code.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One

This topic is closed to new replies.

Advertisement