Work From Home Hack - Keep Your Screen Active Forever Using Python

If your boss is a workaholic and you are not working from the office, then you must have heard one of these statements from your boss,

  • Why were you not at your desk 
  • Why was your status away in Teams/Skype/etc
  • I couldn't see you really putting 8 hours at work, blah blah blah.

Keep Your Screen Active Forever Using Python 
source: launchworkplaces.com

And all these statements are coming because your machine was inactive and that changed your communicator status to Away.

Well, so today we are going to solve this problem wherein we will not let our communicator status change on 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 a 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 the above code, True will run this code indefinitely, until you stop it. Next comes the for loop, which will run 100 times and mouse pointer moves, before it gets paused. 

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 the 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.


Similar Articles