SDL disable keyboard and mouse input
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.
Ok, i have sorted out the mouse by using SDL_ShowCursor(SDL_DISABLE) but what about keyboard?
Yeah, this is just a programming problem, not specifically SDL. Just use a test for your condition like so:
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement