I have a bit of an odd issue relating to hiding the cursor which I just can’t work out the cause.
So, some background first. I have a main application that handles the GUI, and a second (SDL) application that is designed just to handle input. I have my reasons for this but that’s slightly out of scope of this issue.
Upon starting the GUI application it launches the second process (the SDL program) with creates a hidden window. When I need to start capturing input I use IPC to send a message to get SDL to show the window again and capture keyboard & mouse input.
Besides a few quirks I have this more or less working however, for some unknown reason SDL straight up refuses to let me hide the cursor. I’ve tried using windows specific API calls to do it and no luck their either. One very odd thing I have found is that if I hide the cursor from the GUI app it works but this is obviously not what I want. The SDL window has clearly captured the mouse (set relative mouse and cursor is locked to centre) so I’ve no idea how setting the cursor in the GUI app is affecting it when the SDL app has focus??
Anyway, here is some trimmed down code on:
static void ForceFocus(HWND hwnd)
{
SetForegroundWindow(hwnd);
SetCapture(hwnd);
SetFocus(hwnd);
SetActiveWindow(hwnd);
EnableWindow(hwnd, TRUE);
SDL_ShowCursor(SDL_DISABLE);
}
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS ) == 0 )
{
window = SDL_CreateWindow( "Input Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 3440, 1440, SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_HIDDEN | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_ALWAYS_ON_TOP | SDL_WINDOW_SKIP_TASKBAR);
if(window)
{
SDL_SetWindowOpacity(window, 0); //hide window
while ( SDL_WaitEvent(&event) >= 0 && !quit) {
switch (event.type) {
case SDL_GRABINPUT_EVENT: //custom user event
SDL_ShowWindow(window);
/*
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if(SDL_GetWindowWMInfo(window,&info))
{
ForceFocus(info.info.win.window);
}
*/
SDL_SetRelativeMouseMode(SDL_TRUE);
break;
case SDL_UNGRABINPUT_EVENT: //custom user event
SDL_SetRelativeMouseMode(SDL_FALSE);
SDL_HideWindow( window );
break;
}
}
}
else
{
...
}
}
else
{
...
}