Sign in to follow this  

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

This topic is 4842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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