D
D
Dmitry Korolev2019-03-11 18:20:22
C++ / C#
Dmitry Korolev, 2019-03-11 18:20:22

How to determine that the computer is playing video or graphics on the screen?

I have a reminder program to take a break from the screen.
How can I track for it that a video is playing on the screen or the application is on in full screen?
It's like playing a video in a browser and the computer does not turn off the screen while the video is playing.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2019-03-12
@adressmoeistranici

When an application wants to stop the computer from sleeping, it leaves a request to the system through the PowerCreateRequest function .
It seems impossible to get these requests through the public API, because this API does not exist.
But there is a console utility powercfg, if you run it with the -REQUESTS key, it gives a list of active requests. It requires administrator rights to work. Parsing its output is difficult due to localized strings, but for the utility itself, this is not a problem.
When the video is launched in chrome, it showed me this:

DISPLAY:
[PROCESS] \Device\HarddiskVolume2\Program Files (x86)\Google\Chrome\Application\chrome.exe
Playing video

SYSTEM:
[DRIVER] Realtek High Definition Audio (HDAUDIO\FUNC_01&VEN_10EC&DEV_0887&SUBSYS_1458A002&REV_1003\4&3828eb94&0&0201)
Аудиопоток уже используется.
[PROCESS] \Device\HarddiskVolume2\Program Files (x86)\Google\Chrome\Application\chrome.exe
Playing audio

AWAYMODE:
Нет.

From C#, this text can be obtained like this:
var processStartInfo = new ProcessStartInfo("powercfg.exe", "-REQUESTS")
{
    UseShellExecute = false,
    RedirectStandardOutput = true
};

var process = Process.Start(processStartInfo);
var data = process.StandardOutput.ReadToEnd();

1
15432, 2019-03-11
@15432

If it’s a very, very cruel way, then by the number of screen blocks that have changed
https://docs.microsoft.com/en-us/windows/desktop/a...
https://docs.microsoft.com/en-us/windows /desktop/a...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question