Skip to content Skip to sidebar Skip to footer

Can Pyautogui Be Used To Prevent Windows Screen Lock?

I tried to use this script to prevent windows screen lock. The script works for moving the mouse, but it doesn't prevent windows 10 from locking. import pyautogui import time impor

Solution 1:

Yes it can. But sadly not by moving mouse which I don't know why and would like to know. So, my suggestion is to use pyautogui KEYBOARD EVENTS if possible. I have solved my problems by using VOLUME-UP & VOLUME-DOWN keys. Example code is provided below:

import pyautogui
import time

while True:
    pyautogui.press('volumedown')
    time.sleep(1)
    pyautogui.press('volumeup')
    time.sleep(5)

You can use any other keys if you want.

Solution 2:

import ctypes

# prevent
ctypes.windll.kernel32.SetThreadExecutionState(0x80000002)
# set back to normal
ctypes.windll.kernel32.SetThreadExecutionState(0x80000000)

https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setthreadexecutionstate

Tested on python 3.9.1, win 10 64bit

Post a Comment for "Can Pyautogui Be Used To Prevent Windows Screen Lock?"