Last active
October 19, 2020 02:58
-
-
Save aasmith/4315549 to your computer and use it in GitHub Desktop.
Turns off all monitors in Windows using the Win32 API.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Send all monitors to power saving mode (standby) using the WIN32 API. | |
# | |
# Documentation for WM_SYSCOMMAND & SC_MONITORPOWER: | |
# http://msdn.microsoft.com/en-us/library/windows/desktop/ms646360(v=vs.85).aspx | |
require 'fiddle' | |
require 'fiddle/import' | |
require 'fiddle/types' | |
module User32 | |
extend Fiddle::Importer | |
dlload 'user32' | |
include Fiddle::Win32Types | |
extern 'ULONG SendMessage(HWND, UINT, UINT, ULONG)' | |
end | |
HWND_BROADCAST = 0xFFFF | |
WM_SYSCOMMAND = 0x0112 | |
SC_MONITORPOWER = 0xf170 | |
POWER_LOW = 1 | |
POWER_OFF = 2 | |
User32.SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, POWER_OFF) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment