python 实验室定时关闭到时显示器
from ctypes import * import time from ctypes.wintypes import * HWND_BROADCAST = 0xffff WM_SYSCOMMAND = 0x0112 SC_MONITORPOWER = 0xF170 MonitorPowerOff = 2 SW_SHOW = 5 def main(): windll.user32.PostMessageW(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, MonitorPowerOff) shell32 = windll.LoadLibrary('shell32.dll'); shell32.ShellExecuteW(None,'open', 'rundll32.exe', 'USER32,LockWorkStation','',SW_SHOW) # 系统锁定 ''' 利用死循环去调用windows系统下的一个user32.dll动态库达到锁死状态 ''' def lock_windows(): while True: # 调用系统底层下的api ,载入动态库 user32 = windll.LoadLibrary("user32.dll") user32.LockWorkStation() # 锁定键盘 user32.BlockInput(True); time.sleep(30); user32.BlockInput(False); time.sleep(60) print('锁结束') lock_windows() main()