Python PyAutoGUI Script to Keep your PC Alive Forever and Awake it Automatically by Mouse Click or Keyboard and Prevent it From Sleeping Full Project For Beginners

Python PyAutoGUI Script to Keep your PC Alive Forever and Awake it Automatically by Mouse Click or Keyboard and Prevent it From Sleeping Full Project For Beginners

 

Welcome folks today in this blog post we will be preventing our pc from sleeping and awaking it automatically using pyautogui library in python. All the full source code of the application is given below.

 

 

Get Started

 

 

In order to get started you need to install the following library using the pip command as shown below

 

pip install pyautogui

 

After installing this library make an app.py file and copy paste the following code

 

app.py

 

# Import required modules 
import pyautogui 
import time 

# FAILSAFE to FALSE feature is enabled by default 
# so that you can easily stop execution of 
# your pyautogui program by manually moving the 
# mouse to the upper left corner of the screen. 
# Once the mouse is in this location, 
# pyautogui will throw an exception and exit. 
pyautogui.FAILSAFE = False

# We want to run this code for infinite 
# time till we stop it so we use infinite loop now 
while True: 
    
    # time.sleep(t) is used to give a break of 
    # specified time t seconds so that its not 
    # too frequent 
    time.sleep(15) 

    # This for loop is used to move the mouse 
    # pointer to 500 pixels in this case(5*100) 
    for i in range(0, 100): 
        pyautogui.moveTo(0, i * 5) 
        
    # This for loop is used to press keyboard keys, 
    # in this case the harmless key shift key is 
    # used. You can change it according to your 
    # requirement. This works with all keys. 
    for i in range(0, 3): 
        pyautogui.press('shift')

 

See also  Python Tkinter GUI Script to Make Music Mp3 Player Using Pygame,ttkthemes and Mutagen Library Full Tutorial For Beginners

 

And now if you execute the above script by typing the below command

 

python app.py

 

Now if you execute this after some time you haven’t done anything on your pc with your mouse and keyboard this will automatically move your mouse after a specified amount of time

See also  Python 3 Tkinter Script to Build 10 Digit Mobile Number Generator Using Random Module GUI Desktop App Full Project For Beginners

 

Leave a Reply