The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Holding down key while fetching mouse input = choppy mouse
8bitbubsy


Joined: 23 Mar 2017
Posts: 3
Location: Norway
I use streaming textures, and I blit my own mouse cursor and have disabled the OS one. I use SDL 2.0.5 on Windows 10.
In top of my main loop, I do

Code:

SDL_PumpEvents(); /* force reading input events right now */
SDL_GetMouseState(&mx, &my);
/* ... set mouse sprite position ... */


Then lateron I poll events to read keyboard input and so on. However, if I hold down a key so that it repeats while moving the mouse, the mouse movement is choppy.
Is there any way to prevent this? Sounds like the key repeat events are disturbing SDL_GetMouseState().
Holding down a key in my program while moving the mouse is something that is likely to happen, so it's a big problem to me.
capehill


Joined: 13 Feb 2016
Posts: 18
Is there any difference if you handle mouse with SDL_PollEvent?

How many times per second your event loop runs?
8bitbubsy


Joined: 23 Mar 2017
Posts: 3
Location: Norway
No difference with SDL_PollEvent, but you got me thinking regarding the input poll rate... It's 60Hz, that might be the problem. The key repeat is so fast that it's blocking a lot of the input. How can I fix this? Maybe have a different thread for input, then buffer it and read the buffer from the main video thread?
8bitbubsy


Joined: 23 Mar 2017
Posts: 3
Location: Norway
Sorry for the double post, but I managed to overcome this issue by polling the mouse in a separate 100Hz timer thread. Works beautifully now. Please let me know if this is not recommended, for whatever reason.