Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL disable keyboard and mouse input

Started by woody1987 Jan 24, 2009 at 5:32 AM 2 replies 5.8k views
Original Post
woody1987
woody1987
Im writing a simple game and at some point the user has a to move an object across the screen by first clicking the object and then clicking where they would like it placed, this part is working fine, what i want to be able to do is disable all input from the mouse and keyboard while the object is moving. Any help is appreciated.
woody1987
woody1987
Ok, i have sorted out the mouse by using SDL_ShowCursor(SDL_DISABLE) but what about keyboard?
pazoozoo
pazoozoo
Can't you just not do anything with keyboard input while an object is moving?
grimfang4
grimfang4
Yeah, this is just a programming problem, not specifically SDL. Just use a test for your condition like so:

SDL_Event event;bool done = false;while(!done){    while(PollEvent(&event))    {        if(event.type == SDL_QUIT)            done = true;        if(objectIsMoving)        {            // Keyboard and mouse input stuff here        }    }    // Drawing, updating, etc.}



Note that you still need to poll the events, so that you actually discard them. Otherwise, the event queue will fill up and you'll get weird results. Using SDL_ShowCursor(SDL_DISABLE) will hide the mouse cursor, but does not stop events. It is useful when you want to display your own cursor (image) rather than the default one.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.