Skip to main content

Keep Your Screen Active Forever Using Python

If your boss is very workaholic and you are not working from office then you must have heard one of these statements from your boss:
  • Why were you not at your desk 
  • Why your status was away in Teams/Skype/etc
  • I couldn't see you really putting 8 hours at work, blah blah blah.
source: launchworkplaces.com

And all these statements are coming because your machine was inactive and that change your communicator status to Away.
Well, so today we are going to solve this problem where in we will not let our communicator status change by its own.

How can we do that?

Answer is very simple. This problem can be solved, if our machine is active, if we are continuously (or in few mins) pressing some keys or moving our mouse. 
Here we will use Python to write just few lines of code to perform this magic. 

Python package

We will use Python package named pyautogui as it allows us to automate mouse and keyboard interactions. It works very well on Windows, Mac as well as Linux. You can install this package using pip as shown below:


pip install pyautogui     
 

Code

       
  import pyautogui
  import time
  while True:
    for i in range(0,100):
       pyautogui.moveTo(1000,i*10)
    time.sleep(5)      
 

In above code, True will run this code indefinitely, until you stop it. Next comes the for loop, which will run 100 times and mouse mouse pointer, before it gets pause. 

Initial position of mouse pointer will start from x=1000 position. Here timer.sleep(...) is added, so that after every 100 movements, mouse will take a pause of 5 seconds. In actual scenarios, you need to set this timer based on your machine locking time. 

On execution of above code, you will see that your mouse is moving without any human intervention and this will keep your screen active :)

If you want to see this in action, check out my YouTube channel named Shweta Lodha.

Comments