It’s not that I want to do this for any nefarious purpose, but I know some people are actively monitored by their status in Teams, which I consider to be too intrusive. So I made a free Python script to toggle the status of the the Scroll Lock (hardly a useful key) every couple of minutes, and this stops your PC going to sleep, and Teams from showing you as Away. I suppose it might work for other systems too.

You can get it here https://github.com/Ralpharama/PyScrollToggler—PC-Stay-Awake

There’s the code and also a compiled .exe in the repo, details at the end of this page.

This was pretty much copied and adapted from Faisal Khan’s answer here: https://stackoverflow.com/questions/854393/change-keyboard-locks-in-python

The Code

import time
import ctypes
def toggle_scroll_lock():
dll = ctypes.WinDLL('User32.dll')
VK_SCROLL = 0x91
if not dll.GetKeyState(VK_SCROLL):
dll.keybd_event(VK_SCROLL, 0X3a, 0X1, 0)
dll.keybd_event(VK_SCROLL, 0X3a, 0X3, 0)
else:
dll.keybd_event(VK_SCROLL, 0X3a, 0X1, 1)
dll.keybd_event(VK_SCROLL, 0X3a, 0X3, 1)
print('Running PyScrollToggler… CTRL+C twice to stop.')
while(True):
  toggle_scroll_lock()
  time.sleep(200)

I think the code is pretty self-explanatory!

Enjoy!

Purpose

Toggles the scroll lock on and off every 200 seconds on a Microsoft Windows machine. This will stop many programs that time out due to inactivity from doing so for example, Windows screensaver, Microsoft Teams, etc. Thanks to Faisal Khan for the base code on StackOverflow. Just start the program and leave it running minimized. Tested working with Teams in Dec 2022.

This uses virtually zero CPU as it just sleeps between toggles, and takes up about 6MB of memory when running.

Running the program

You can run the .py file directly if you have python installed:

C:\> cd c:\path-to-the-file
C:\path-to-the-file> py PyScrollToggler.py

If you can’t open a command prompt, try Right-Click Start/Run, then enter:

py c:\path-to-the-file\PyScrollToggler.py

Or download and run the exe in the dist folder (which was made with pyinstaller).

Last modified: January 4, 2023

Author

Comments

Write a Reply or Comment

Your email address will not be published.