Question / Help OBS Prevents screen sleep, any work around?

qbn

New Member
Hi, as the title indicates, simply having OBS opens prevents the display from sleeping or the screensaver to kick in. Is there anyway to prevent this? I understand when recording or streaming, but otherwise having it open should allow the display to sleep, or at least be an option.
 

koala

Active Member
OBS always does its internal rendering, streaming or not, running minimized or not, preview active or not. To be able to do this, OBS needs a physical GPU. If the screensaver kicks in, or if the machine goes to sleep, the GPU is taken away by Windows and OBS fails, so OBS prevents Windows from doing all this.
If you want to allow Windows to go to sleep, terminate OBS.
If you want to activate the screensaver while you're away (for privacy reasons), press Windows-L to lock the screen immediately.
 

fluffycritter

New Member
Hi, I realize this is a really old thread but I don't see anything more recent, and it felt redundant to start a new thread.

Would it be possible to give OBS an option to allow the system to sleep while there's no streaming or recording happening? I have a machine dedicated to streaming and I'm always forgetting to quit OBS when it's not in use, and I'd like to help save the planet by not wasting so much electricity all the time.

Based on what @koala said it seems like it might be possible to unlock the GPU resources while a stream's not active, and relock it when it needs to. But of course I'm sure that's easier said than done. :)
 

Eric_K

New Member
I have been searching for a good workaround for a long time. Finally I gave up and just programmed a macro to kill OBS directly and then Sleep the PC for me with one keypress. I assigned it to the Sleep key on my keyboard and it works well.

In case you want to do something similar, the command to kill OBS without additional prompting is:

"taskkill /f /im obs64.exe"

Depending on how your keyboard / macro software applies macros, you may need to open a Run dialog to execute the command. For example: 'Win+R, taskkill /f /im obs64.exe, Enter'. Don't forget to tack on your sleep hotkey at the end to complete the actual sleep command.

Btw, if you don't have a sleep hotkey you could use 'Win+x, u, s' which will bring up the Windows Power-User Menu for you, select 'Shutdown and Signout', and then select 'Sleep'. When using key-combos like this to Sleep, I also recommend adding 'Esc' at the very end, so that when the PC wakes, the Esc will close the Run dialog automatically.

I hope this is helpful to someone out there. :-)
 

Eric_K

New Member
BTW, I realize that my workaround above doesn't do anything to help with the OPs screen saver issue, but perhaps the command below would be helpful in automating some sort of DIY screen saver:

powershell (Add-Type '[DllImport(\"user32.dll\")]^public static extern int PostMessage(int hWnd, int hMsg, int wParam, int lParam);' -Name a -Pas)::PostMessage(-1,0x0112,0xF170,2)

The command turns off the screen(s) but leaves the PC running (much like Windows built-in screen saver) except that it works even if OBS is running. Hitting any key or moving the mouse will wake the the screen(s).

On my system, I put the command into a one-line batch file and assigned a hotkey to launch it, giving me options to either sleep the entire system or just sleep the screen using a key press.
 

llinfeng

New Member
How about forcing the monitors to go off? (This won't get screensaver working, though.)
  • Option 1: use nircmd.exe monitor off. (Source + Ref)
  • Option 2: use AutoHotKey to execute "postMessage,0x112,0xF170,2,,Program Manager" via a keyboard shortcut. Here is a first attempt assigning Win + L to turn off the monitors.
    Code:
    #l::
    postMessage,0x112,0xF170,2,,Program Manager
    return
    At least on Win10, with Win+L, the machine is locked and the monitors went off. On Win 11, though, the script is still working as intended, but the OS was turning the monitor back on to show us the lock screen after a few seconds.
 

tbobs22

New Member
I only use the virtual webcam in OBS and have the same problem. When my online meeting is done, system won't sleep, because virtual camera is activated, even though I don't use it anymore in the meeting application.

Possible solution:
You can use "powercfg.exe -requests" to see which software/driver is preventing display/system standby.
>powercfg -requests DISPLAY: [PROCESS] \Device\HarddiskVolume3\..\obs-studio\bin\64bit\obs64.exe SYSTEM: [PROCESS] \Device\HarddiskVolume3\..\obs-studio\bin\64bit\obs64.exe [DRIVER] Legacykernelaufrufer AWAYMODE: [PROCESS] \Device\HarddiskVolume3\..\obs-studio\bin\64bit\obs64.exe

Then use "powercfg.exe -requestsoverride .." to make the system ignore resources claimed by obs64.exe. Lookup detailed syntax on the web or try "powercfg.exe /?". I've used this method successfully for other applications for which I don't want display/system sleep to be prevented (music player or connection to a remote system e.g.)

I just noticed there is some kind of python scripting in OBS as well, maybe that is another option (stop virtual camera automatically?).
Whether this will work depends on the scripting API and how complex it is (does it handle events?), I need to look into it, but just to give another possible direction.
 

adolling

New Member
Hmm. I've been investigating and solving this puzzle for a while.
Using the powercfg -requests command shows obs64.exe when the virtual camera is on, but not when it is stopped.

I don't stream or record, but suggest trying to make sure that the virtual camera is stopped.
 

SmokeySynapse

New Member
Hello everyone,

I created an account just to reply on this thread - thank you for allowing me to not have to spend hours searching if this is possible.

I also found a work around is to remote desktop connect to the host PC and then you can lock the PC you remoted in with too and OBS continues to render.

It's kinda shit that I can't just lock the PC though...
 

Charles_Mcgill

New Member
I use OBS for the Replay Buffer function, so OBS was always running and preventing sleep.

If you have the 64 bit version the solution I found was to open the Command Prompt as administrator and use this command:
powercfg -requestsoverride process obs64.exe display system awaymode

You'll know if you did it right if you use powercfg -requestsoverride and see
"obs64.exe DISPLAY SYSTEM AWAYMODE" under [PROCESS]

Hope this helps.
 

whitelotus

New Member
I use OBS for the Replay Buffer function, so OBS was always running and preventing sleep.

If you have the 64 bit version the solution I found was to open the Command Prompt as administrator and use this command:
powercfg -requestsoverride process obs64.exe display system awaymode

You'll know if you did it right if you use powercfg -requestsoverride and see
"obs64.exe DISPLAY SYSTEM AWAYMODE" under [PROCESS]

Hope this helps.
I love you I use obs the same way and it did help.
 

Datulipan

New Member
Along comes ChatGPT which solves this issue for me in a couple of minutes.

Basically, I don't want my computer to go to sleep, but I do want my monitor to turn off (standby mode) and lock screen to be activated.

This script is designed to monitor a user's inactivity based on their keyboard and mouse inputs. If the user remains inactive beyond a specified duration (in minutes), the script will automatically lock the workstation and put the monitor to sleep.

Seems to be working well for me, however I'm going to do a bit of testing before I add it as a scheduled task and trigger when the workstation is uunlocked.

** update ** - needs a bit of work.. IE gracefully stopping OBS before running the lock screen a monitor standby commands.. But hopefully serves as a good starting point. Maybe later include an option to check if OBS is actually recording once the timer is reached. But for now, it's a good starting point.

Code:
<#
.SYNOPSIS
LockScreenIdleMonitor.ps1 monitors the user's idle time based on mouse and keyboard activity and locks the screen or puts the monitor into standby when certain idle thresholds are reached.

.DESCRIPTION
LockScreenIdleMonitor.ps1 uses the Windows API to detect the last user activity (from keyboard or mouse).
When the user's cumulative idle time reaches specific thresholds (specified in minutes), the script can
lock the workstation and/or put the monitor to sleep.

.NOTES
File Name      : LockScreenIdleMonitor.ps1
Author         : ChatGPT from OpenAI
Prerequisite   : PowerShell V2
Copyright 2023 : OpenAI
#>

if (-not ([System.Management.Automation.PSTypeName]'IdleActions').Type) {
    Add-Type @'
    using System;
    using System.Runtime.InteropServices;

    public static class IdleActions {
        [DllImport("user32.dll", SetLastError=false)]
        public static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);

        [DllImport("user32.dll")]
        public static extern void LockWorkStation();

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SendMessage(int hWnd, int wMsg, int wParam, int lParam);

        [StructLayout(LayoutKind.Sequential)]
        public struct LASTINPUTINFO {
            public uint cbSize;
            public uint dwTime;
        }

        public static uint GetIdleDuration() {
            LASTINPUTINFO lii = new LASTINPUTINFO();
            lii.cbSize = (uint)Marshal.SizeOf(typeof(LASTINPUTINFO));
            GetLastInputInfo(ref lii);
            return ((uint)Environment.TickCount - lii.dwTime);
        }
    }
'@
}

function Monitor-IdleTime {
    param (
        [Parameter(Mandatory=$true)]
        [int]$LockScreenThresholdMinutes,
       
        [Parameter(Mandatory=$true)]
        [int]$MonitorStandbyThresholdMinutes
    )

    # Constants for monitor sleep and activation
    $SC_MONITORPOWER = 0xF170
    $WM_SYSCOMMAND = 0x0112
    $MONITOR_OFF = 2
    $HWND_BROADCAST = 0xFFFF

    $lockThresholdSeconds = $LockScreenThresholdMinutes * 60
    $monitorThresholdSeconds = $MonitorStandbyThresholdMinutes * 60

    while ($true) {
        $idleTime = [IdleActions]::GetIdleDuration()

        # Convert idleTime from milliseconds to seconds
        $idleSeconds = $idleTime / 1000

        if ($idleSeconds -ge $lockThresholdSeconds) {
            [IdleActions]::LockWorkStation()
            # Once locked, we reset the idleSeconds to not immediately turn off the monitor post-lock
            $idleSeconds = 0
        }

        if ($idleSeconds -ge $monitorThresholdSeconds) {
            [IdleActions]::SendMessage($HWND_BROADCAST, $WM_SYSCOMMAND, $SC_MONITORPOWER, $MONITOR_OFF)
        }

        Clear
        Write-Output ("Idle for: {0:D2}:{1:D2}" -f [int]($idleSeconds / 60), [int]($idleSeconds % 60))

        Start-Sleep -Seconds 5
    }
}

Monitor-IdleTime -LockScreenThresholdMinutes 5 -MonitorStandbyThresholdMinutes 10
 

Charles_Mcgill

New Member
Along comes ChatGPT which solves this issue for me in a couple of minutes.

Basically, I don't want my computer to go to sleep, but I do want my monitor to turn off (standby mode) and lock screen to be activated.

This script is designed to monitor a user's inactivity based on their keyboard and mouse inputs. If the user remains inactive beyond a specified duration (in minutes), the script will automatically lock the workstation and put the monitor to sleep.

Seems to be working well for me, however I'm going to do a bit of testing before I add it as a scheduled task and trigger when the workstation is uunlocked.

** update ** - needs a bit of work.. IE gracefully stopping OBS before running the lock screen a monitor standby commands.. But hopefully serves as a good starting point. Maybe later include an option to check if OBS is actually recording once the timer is reached. But for now, it's a good starting point.

Code:
<#
.SYNOPSIS
LockScreenIdleMonitor.ps1 monitors the user's idle time based on mouse and keyboard activity and locks the screen or puts the monitor into standby when certain idle thresholds are reached.

.DESCRIPTION
LockScreenIdleMonitor.ps1 uses the Windows API to detect the last user activity (from keyboard or mouse).
When the user's cumulative idle time reaches specific thresholds (specified in minutes), the script can
lock the workstation and/or put the monitor to sleep.

.NOTES
File Name      : LockScreenIdleMonitor.ps1
Author         : ChatGPT from OpenAI
Prerequisite   : PowerShell V2
Copyright 2023 : OpenAI
#>

if (-not ([System.Management.Automation.PSTypeName]'IdleActions').Type) {
    Add-Type @'
    using System;
    using System.Runtime.InteropServices;

    public static class IdleActions {
        [DllImport("user32.dll", SetLastError=false)]
        public static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);

        [DllImport("user32.dll")]
        public static extern void LockWorkStation();

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SendMessage(int hWnd, int wMsg, int wParam, int lParam);

        [StructLayout(LayoutKind.Sequential)]
        public struct LASTINPUTINFO {
            public uint cbSize;
            public uint dwTime;
        }

        public static uint GetIdleDuration() {
            LASTINPUTINFO lii = new LASTINPUTINFO();
            lii.cbSize = (uint)Marshal.SizeOf(typeof(LASTINPUTINFO));
            GetLastInputInfo(ref lii);
            return ((uint)Environment.TickCount - lii.dwTime);
        }
    }
'@
}

function Monitor-IdleTime {
    param (
        [Parameter(Mandatory=$true)]
        [int]$LockScreenThresholdMinutes,
      
        [Parameter(Mandatory=$true)]
        [int]$MonitorStandbyThresholdMinutes
    )

    # Constants for monitor sleep and activation
    $SC_MONITORPOWER = 0xF170
    $WM_SYSCOMMAND = 0x0112
    $MONITOR_OFF = 2
    $HWND_BROADCAST = 0xFFFF

    $lockThresholdSeconds = $LockScreenThresholdMinutes * 60
    $monitorThresholdSeconds = $MonitorStandbyThresholdMinutes * 60

    while ($true) {
        $idleTime = [IdleActions]::GetIdleDuration()

        # Convert idleTime from milliseconds to seconds
        $idleSeconds = $idleTime / 1000

        if ($idleSeconds -ge $lockThresholdSeconds) {
            [IdleActions]::LockWorkStation()
            # Once locked, we reset the idleSeconds to not immediately turn off the monitor post-lock
            $idleSeconds = 0
        }

        if ($idleSeconds -ge $monitorThresholdSeconds) {
            [IdleActions]::SendMessage($HWND_BROADCAST, $WM_SYSCOMMAND, $SC_MONITORPOWER, $MONITOR_OFF)
        }

        Clear
        Write-Output ("Idle for: {0:D2}:{1:D2}" -f [int]($idleSeconds / 60), [int]($idleSeconds % 60))

        Start-Sleep -Seconds 5
    }
}

Monitor-IdleTime -LockScreenThresholdMinutes 5 -MonitorStandbyThresholdMinutes 10
My posted solution above also works for turning off monitors using the "Turn off the display" setting under the power plan settings in control panel. No need for a script.
 

probablypablito

New Member
I use OBS for the Replay Buffer function, so OBS was always running and preventing sleep.

If you have the 64 bit version the solution I found was to open the Command Prompt as administrator and use this command:
powercfg -requestsoverride process obs64.exe display system awaymode

You'll know if you did it right if you use powercfg -requestsoverride and see
"obs64.exe DISPLAY SYSTEM AWAYMODE" under [PROCESS]

Hope this helps.
Does this need to be run every time OBS is launched or will it permanently save? I'm assuming the former since you're not input a full path to the binary.
 
Top