Building a no sleep app

tags
dev
type
Post
summary
A walk through on how to build a no sleep screen app in python
status
Published
Text
slug
Files & media
date
Jan 31, 2025
notion image
 

How the idea was born

One day my mom was working from home so she could keep up with the house work since Ramadan was right around the corner and we were expecting guest, it was a good time to clear things up, but whenever she went to do some kitchen work her laptop’s screen would sleep and her activity on the teams platform would update to to inactive which was a problem for her so she kept asking everyone in the house to give it a quick tap every now and then so it would stay on.
It was okay at first but as time passed by it started to feel like an unnecessary chore that kept me distracted.
Then it hit me, I could have just automated this easily a longtime ago!
 
notion image
 

Concept

To start things off this project is going to be on Python.
In order to keep your screen from sleeping it has to have some kind of activity that keeps it on. For that I’ll be using pyautogui . For those who don’t know pyautogui is a Python library that can be used to manipulate different Mouse and Keyboard function in creative ways like creating local automations.
For this project we only be using one function from pyautogui which is the .moveTo() function which moves the mouse’s position based on the inserted coordinates.
 

To the Build

 
  1. Assuming you have python on your machine run the following command:
  1. In a folder create a new file and name it main.py then import the following packages
  1. Setup your variables as shown below
  1. Create a loop that modifies the position of the cursor randomly from 0 to 1080(both X and Y axis)
 
Your final code should look something like this :
 
Once your done with this code use the following command in your project folder to run it
notion image
Once your done it should look something like this. It’s not much but it’s honest work.
 
I know it’s pretty barebone as it is but this was the very first iteration that worked promisingly well but over time I made another iteration with a UI that made it simple for terminalphobic people to use it with ease
 
notion image
Here is the code if you want to try it out yourself
 

Conclusion

There are probably more efficient techniques on how to keep your screen ON seamlessly but it’s a fun project to build and can help you understand basic automation. It helped a good number of people around me do exactly what it’s supposed to do.
 
Hope you enjoyed the article😁
 

Powered by Notion and Next.js

© Ihsan 2025