Sign in to follow this  

SDL. How to disable mouse ?

This topic is 3150 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

My program lags when I move the pointer around the screen, so I need to disable it. Pretty common problem, but the usual answer is: SDL_ShowCursor(0); which doesn't work for me because it only hides it, while I need my game to ignore\disable any mouse input so it won't be counted in the SDL_PollEvent. Is that possible ?

Share this post


Link to post
Share on other sites
I have never noticed such lags, how does your event loop looks like?
Are you handling all events every frame?

// main loop
while(1){
// event loop
while(SDL_PollEvent(&event)) {
...
}
...
}

Share this post


Link to post
Share on other sites
Yes,

while(gameRunning)
{
//draw sprite here

if(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
gameRunning=false;

if(event.type == SDL_KEYDOWN)
{
keyHold[event.key.keysym.sym] = true;
}

if(event.type == SDL_KEYUP)
{
keyHold[event.key.keysym.sym] = false;
}

}

//keyHold[] array stores values for every key, so the character
//moves constantly on KEYDOWN and stops on KEYUP.

if(keyHold[SDLK_ESCAPE])
gameRunning = false;

if( keyHold[SDLK_LEFT] )
{
Player->moveLeft();
}
if( keyHold[SDLK_UP] )
{
Player->moveUp();
}
if( keyHold[SDLK_DOWN] )
{
Player->moveDown();
}
if( keyHold[SDLK_RIGHT] )
{
Player->moveRight();
}

}

Share this post


Link to post
Share on other sites
Quote:
Original post by danDemon
Yes. I use input method similar to the one posted in Aaron's tutorial:

http://www.aaroncox.net/tutorials/2dtutorials/sdlkeyboard.html


That tutorial is checking just one event per frame:

if (SDL_PollEvent(&event)) ...


notice that I had a while instead of the if.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kambiz
Quote:
Original post by danDemon
Yes. I use input method similar to the one posted in Aaron's tutorial:

http://www.aaroncox.net/tutorials/2dtutorials/sdlkeyboard.html


That tutorial is checking just one event per frame:

if (SDL_PollEvent(&event)) ...


notice that I had a while instead of the if.


Damn I would never suspect simple operation would fix the problem, thanks a LOT man! :)

Share this post


Link to post
Share on other sites
Quote:
Original post by danDemon
while I need my game to ignore\disable any mouse input so it won't be counted in the SDL_PollEvent.

Is that possible ?

This is only posted for completeness of the thread, as the OP's problem is fixed.
Yes if this is really what you want. You can set up an event filter in which you can decide if to allow the event onto the queue. This enables you to switch the mouse events on and off at your will. There is a special note to take into consideration, this being that mouse wheel events are sent as button events. Alternately if you never want to get the events then simply set the state to ignore using SDL_EventState.

Share this post


Link to post
Share on other sites

This topic is 3150 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