Cursor disappears when moved

Hi all,

After setting my video mode to full screen, my code does an
SDL_ShowCursor(SDL_DISABLE). After the screen switches to full screen, the
mouse does not appear. This works fine in Windows XP.

Unfortunately my target platform in a Windows 98 box. And for some reason, when
the same program runs on that machine, after the screen switches to full screen
mode, the mouse cursor remains in the middle of the screen. However, as soon as
the mouse is moved, it disappears. Unfortunately, the user doesn’t have access
to the mouse upon startup (only the keyboard).

Is there any trick I can use to programmatically hide the mouse cursor other
than using SDL_ShowCursor(SDL_DISABLE)?–
Mark Jenison

Is there any trick I can use to programmatically hide the mouse cursor other
than using SDL_ShowCursor(SDL_DISABLE)?

Try this: when you get the SDL_ACTIVEEVENT event, check if you’re in
fullscreen mode and gained focus, and if so call SDL_ShowCursor
(SDL_DISABLE). One way to check if the app gained focus is this:

if(SDL_GetAppState() & SDL_APPINPUTFOCUS)

Ilya Olevsky <info valengames.com> writes:

Is there any trick I can use to programmatically hide the mouse cursor other
than using SDL_ShowCursor(SDL_DISABLE)?

Try this: when you get the SDL_ACTIVEEVENT event, check if you’re in
fullscreen mode and gained focus, and if so call SDL_ShowCursor
(SDL_DISABLE). One way to check if the app gained focus is this:

if(SDL_GetAppState() & SDL_APPINPUTFOCUS)

Thanks for the advice.

I put this check in my main code loop, and when the program starts up now, the
cursor is hidden.

However, if later something happens on the system that causes the cursor to
become an hourglass (disk access, etc), it causes the cursor to reappear. I
would think this code would correctly re-hide the cursor, but it does not. Any
other ideas?

Thanks for the advice.

I put this check in my main code loop, and when the program starts up now, the
cursor is hidden.

However, if later something happens on the system that causes the cursor to
become an hourglass (disk access, etc), it causes the cursor to reappear. I
would think this code would correctly re-hide the cursor, but it does not. Any
other ideas?

Hmm… That’s weird, but then again I’ve seen Win98/ME do stranger
things. Try calling SDL_WM_GrabInput(SDL_GRAB_ON) after you init
everything, if you don’t do it already. If that doesn’t help, try hiding
the cursor when the app gains mouse focus (on SDL_APPMOUSEFOCUS instead
of SDL_APPINPUTFOCUS) or just check against SDL_APPACTIVE when you get
an SDL_ACTIVEEVENT. That’s pretty much all I can think of other than
checking every frame if the mouse is visible.

Ilya

Ilya Olevsky <info valengames.com> writes:

Thanks for the advice.

I put this check in my main code loop, and when the program starts up now,
the

cursor is hidden.

However, if later something happens on the system that causes the cursor to
become an hourglass (disk access, etc), it causes the cursor to reappear.
I

would think this code would correctly re-hide the cursor, but it does not.
Any

other ideas?

Hmm… That’s weird, but then again I’ve seen Win98/ME do stranger
things. Try calling SDL_WM_GrabInput(SDL_GRAB_ON) after you init
everything, if you don’t do it already. If that doesn’t help, try hiding
the cursor when the app gains mouse focus (on SDL_APPMOUSEFOCUS instead
of SDL_APPINPUTFOCUS) or just check against SDL_APPACTIVE when you get
an SDL_ACTIVEEVENT. That’s pretty much all I can think of other than
checking every frame if the mouse is visible.

Ilya

Ok, it seems that it’s a crap shoot whether or not the mouse is already
visible upon startup…sometimes it is there, sometimes not. I tried the
SDL_WM_GrabInput, but that seemed to make it worse.

This is basically the logic I have (I don’t use the mouse at all in this app,
just joystick and keyboard):

int main()
{

if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
{
// report error
}

input_startup() (initialize keyboard, joystick)

graphics_startup (set video mode, etc)

while (!finished)
{

if (ready to draw)
{
// draw screen
}

while(frame_count > 0)
{
next_frame();
handle_events(); (keyboard events)
update_screen();
frame_count–;
}

if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)
|| (SDL_GetAppState() & SDL_APPINPUTFOCUS)
|| (SDL_GetAppStaet() & SDL_APPACTIVE))
{
SDL_ShowCursor(SDL_DISABLE);
}
}
}

If the app starts with the cursor hidden, the cursor appears later at a random
time (seems like it may be due to the system doing some background processing).
But I would think the above code would hide it if it appeared later?

Again, simply pressing a button on the mouse or moving the mouse causes the
cursor to disappear again.

Any other suggestions?

Any other suggestions?

Can you reproduce it with any of the SDL test programs? If so, can you
post which one, and any modifications you needed to make to reproduce it?

Also, feel free to create a bug report at http://bugzilla.libsdl.org

Thanks!
-Sam Lantinga, Senior Software Engineer, Blizzard Entertainment