setScreenSaverEnabled may have undesired sideffects


#1

Hello Jules,

In some of our GUIS we have enabled setScreenSaverEnabled and it works great!!!

However we discovered a hidden nasty side-effect :frowning:

A bit of background

The ScreenSaverDefeater start a 10 seconds timeout that automatically simulates a shift key. If you have more than two languages, the behavior by default in Windows XP and Windows 7 if you press “CTRL” + “SHIFT” is to change the language. Therefore, if you keep the “CTRL” key down, and wait 10 seconds after calling setScreenSaverEnabled(false), the keyboard/language setup will change by itself. (This may be even nastier in WIndows XP when a WM_INPUTLANGCHANGEREQUEST is sent to the event loop, but lets not get side tracked).

The scenario is plausible if you imagine someone doing a lot of copy / paste…

To work around it, I have tried to replace the simulated shift key with a simulated mouse move of 0, i.e. :

I also tried

mouse_event( MOUSEEVENTF_MOVE, 1,0 , 0, NULL ); mouse_event( MOUSEEVENTF_MOVE, -1,0 , 0, NULL );
but the one with 0 seems fine too.

I was going to ask for your expert opinion if you can think of anything wrong with doing this instead of the shift key.

Thank you very much for your help and opinion


#2

Interesting. Good point.

mouse_event is a deprecated function though - can the same thing be done with SendEvent?


#3

e.g.

[code] void timerCallback()
{
if (Process::isForegroundProcess())
{
INPUT input = { 0 };
input.type = INPUT_MOUSE;
input.mi.mouseData = MOUSEEVENTF_MOVE;

        SendInput (1, &input, sizeof (INPUT));
    }
}

[/code]

?


#4

Thank you very much for the quick reply and improvement suggested. I tested it and it works great on our machines on Windows 7 and XP, I shall keep it,

Cheers,