Answer the question
In order to leave comments, you need to log in
Is there a cross-platform (desktop) way to prevent the computer from going to sleep?
Does anyone know how to use Qt or just cross-platform (Mac, *nix, Win) to keep the computer from falling asleep?
Found only on WinAPI .
Answer the question
In order to leave comments, you need to log in
Insert the plug into the keyboard - it will constantly send a signal about activity.
Maybe somehow it is possible to simulate the user's work at the computer, for example, after a short period of time, move the cursor or simulate pressing a key that is useless in the program frame?
You can track inactivity like this, for example: How to track user inactivity in QT?
I suppose there is no cross-platform way.
Here is an example for Windows:
//--------------------------------------------------------------------------------
void ISysUtils::displayOn(bool aOn)
{
enum {
DISPLAY_ON = -1,
DISPLAY_OFF = 2
};
if (aOn)
{
PostMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, DISPLAY_ON);
// имитируем дёргание мышки для включения монитора в Windows 8
INPUT input;
SecureZeroMemory(&input, sizeof(input));
input.type = INPUT_MOUSE;
input.mi.dy = 1;
input.mi.dwFlags = MOUSEEVENTF_MOVE;
SendInput(1, &input, sizeof(input));
SleepEx(40, TRUE);
input.mi.dy = -1;
SendInput(1, &input, sizeof(input));
}
else
{
PostMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, DISPLAY_OFF);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question