Last active
February 24, 2023 04:13
-
-
Save sharow/78042aea55a8d69a1e05f33960ec8752 to your computer and use it in GitHub Desktop.
win: sleep monitor immediately
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
# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; coding: utf-8; -*- | |
from ctypes import * | |
user32 = WinDLL('User32') | |
DISPLAY_ON = -1 | |
DISPLAY_OFF = 2 | |
HWND_BROADCAST = 0xffff | |
WM_SYSCOMMAND = 0x0112 | |
SC_MONITORPOWER = 0xf170 | |
post_message = cast(user32.PostMessageA, | |
CFUNCTYPE(c_uint32, c_uint32, c_uint32, c_uint32, c_uint32)) | |
lock_workstation = cast(user32.LockWorkStation, CFUNCTYPE(c_uint32)) | |
post_message(HWND_BROADCAST, | |
WM_SYSCOMMAND, | |
SC_MONITORPOWER, | |
DISPLAY_OFF) | |
# lock_workstation() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment