DEV Community

Shashank Mishra
Shashank Mishra

Posted on

WFH Tip: Prevent Windows Locking

I am a CS engineer and working from home since March 2020. I haven’t been to my office since the last 4–5 months (WFH all the way!!).

I have a dual monitor setup with my laptop, Xbox One and a third screen of the HP Probook (provided by my organization).

The problem

When I am working on my personal laptop for extensive periods or streaming on Twitch (spartan_259 🎮), i.e. not using the office laptop, it would automatically lock. This would prevent any notifications from Microsoft Teams, Skype (would show my status as inactive, it doesn't look good) or even Outlook. As I don't have administrator rights so I couldn’t change the settings. This was an issue for me.

To prevent Windows from locking one can play a YouTube video at all times or maybe keep some keyboard button pressed or some other OOB method. We all must agree here that none of these are practical.

Solution

I wrote a Python script ( I 💖 Python).

I have used a keypress simulation, I tried with a mouse cursor movement but it didn't work (Windows would lock and eventually sleep).

When the script is executed, it asks for the key which keypress has to be simulated. A small note here, this code will keep running (infinite loop) and has to be manually stopped (CTRL + C).

I guess for most of us it would suffice. 😁

  • Uses around 15mb of RAM and less than 1% of CPU (Windows Task Manager stats)
  • Skype/Teams would always show Available -- Ultimate goal, wouldn't want to upset the boss | I don't use my office laptop whole day.

I am working on a more feature rich version. Would update soon!

Output

Prevent Windows lock
Enter keyboard button: capslock
Running
Enter fullscreen mode Exit fullscreen mode

The script will prompt to enter a keyboard button, following buttons are supported -
https://pyautogui.readthedocs.io/en/latest/keyboard.html#keyboard-keys

Thanks for reading, I hope this helps.

Top comments (1)

Collapse
 
bearddude profile image
Raghavendran Ramesh

Hi Shashank, Just curious to know why .press was used twice here.
As per the docs,
The press() function is really just a wrapper for the keyDown() and keyUp() functions, which simulate pressing a key down and then releasing it up.