How can I get my display to turn off on-demand?
Right now my win 10 PC is set to turn off the display after 30 minutes of inactivity. I'm wondering if I can have that same function on-demand. I often use my PC at night before going to sleep and want to be able to turn off the display from my wireless keyboard. I know this keyboard has a sleep button, but sometimes I do not want to put my computer to sleep due to downloads or other processes still running. So I'm wondering if there is anyway I can have some .bat file, or other method of just turning off the screen without having to get up and press the button on my monitor. It would be awesome if I could wire it up to a button on my keyboard too, just like sleep is.
Thanks!
Based on this Windows 7 answer which links to this script page, and checking this MSDN library page, that the codes used are correct you can run the powershell script below to switch the screen off. I ran it on my Windows 10 laptop and it worked fine. Moving the mouse after running the script wakes up the screen like you normally do when the screen has turned off from the power save feature.
The 2 second delay before it turns off the screen is so that you can have time to let go of the mouse/keyboard before Windows starts checking for movement for turning the screen back on.
Using this powershell script, you do not need any third party tool or need to mess with your existing settings. Just save it in a file with a .ps1 file extension and run it with powershell.
# Turn display off by calling WindowsAPI.
# SendMessage(HWND_BROADCAST,WM_SYSCOMMAND, SC_MONITORPOWER, POWER_OFF)
# HWND_BROADCAST 0xffff
# WM_SYSCOMMAND 0x0112
# SC_MONITORPOWER 0xf170
# POWER_OFF 0x0002
Add-Type -TypeDefinition '
using System;
using System.Runtime.InteropServices;
namespace Utilities {
public static class Display
{
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SendMessage(
IntPtr hWnd,
UInt32 Msg,
IntPtr wParam,
IntPtr lParam
);
public static void PowerOff ()
{
SendMessage(
(IntPtr)0xffff, // HWND_BROADCAST
0x0112, // WM_SYSCOMMAND
(IntPtr)0xf170, // SC_MONITORPOWER
(IntPtr)0x0002 // POWER_OFF
);
}
}
}
'
start-sleep 2
[Utilities.Display]::PowerOff()
I'm wondering if I can have that same function on-demand.
Use nircmd from nirsoft (if it is supported by your monitor):
nircmd monitor off
monitor [action]
Changes the state of the display monitor. The
[action]
parameter may contain the following values:
off
: Turn off the monitoron
: Turn on the monitorlow
: Set the monitor to low power state.This command only works in systems that support this feature. If you have a problem that NirCmd remains in memory when using this command, you may try to use
async_off
,async_on
andasync_low
actions instead ofon/off/low
actions.
Source NirCmd Command Reference - monitor
Disclaimer
I am not affiliated with nirsoft in any way, I am just an end user of their software.