Reputation: 21
I'm in the middle of making a Python script to shutdown, restart, hibernate or put to sleep after a few seconds.
I know its subprocess.call(["shutdown", "/s"])
to shutdown, "/r"
to restart and "/h"
to hibernate.
How can you put the computer to sleep using call()
on Windows 10?
Upvotes: 2
Views: 1302
Reputation: 11
I know this is asked 3 years ago, but if anyone looking for help, I found a way for sleep with pyautogui
First download and install pyautogui with terminal using command pip download pyautogui and pip install pyautogui
import pyautogui
pyautogui.hotkey("alt", "f4") time.sleep(1) pyautogui.press("left") time.sleep(1) pyautogui.press("enter")
Visit this website if you need any help with pyautogui commands
(I am too new to python coding, there must be easy and more suitable ways to do this. Sorry if I sound so noob.)
Upvotes: 1
Reputation: 1885
Shutdown doesn't have a function for Sleep integrated however you can use the following: rundll32.exe powrprof.dll,SetSuspendState 0,1,0
Upvotes: 2