S
S
Sergey Savostin2016-01-28 11:11:00
Qt
Sergey Savostin, 2016-01-28 11:11:00

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

3 answer(s)
G
GavriKos, 2016-01-28
@GavriKos

Insert the plug into the keyboard - it will constantly send a signal about activity.

E
EXL, 2016-01-28
@EXL

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?

A
Alexey Obukhov, 2016-02-23
@Obukhoff

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 question

Ask a Question

731 491 924 answers to any question