The following script simply toggles the SCROLL-LOCK key every 4 minutes with a .1s double click.
To use: save this as a Powershell script (ending with .ps1) and then run it. Once open, just minimize the script window. It'll still run fine minimized.
clear-host
Echo "Keep alive with scroll lock"
$WShell = New-Object -com "WScript.shell"
while ($True)
{
$WShell.sendkeys("{SCROLLLOCK}")
start-sleep -Milliseconds 100
$WShell.sendkeys("{SCROLLLOCK}")
start-sleep -Seconds 240
}
Echo "Keep alive with scroll lock"
$WShell = New-Object -com "WScript.shell"
while ($True)
{
$WShell.sendkeys("{SCROLLLOCK}")
start-sleep -Milliseconds 100
$WShell.sendkeys("{SCROLLLOCK}")
start-sleep -Seconds 240
}
An alternative script I wrote gives more detail. I have it pressing the Num Lock Key on a random schedule from 0 to 30 minutes.
cls
Echo "Keep alive with NUMLOCK"
$WShell = New-Object -com "WScript.shell"
while ($True)
{
$rand=Get-Random -Maximum 1800
$randminutes=$rand/60
$ts = New-TimeSpan -Seconds $rand
Write-Host "$([math]::Round($randminutes,2)) Minutes Start($(Get-Date)) End($((Get-Date)+$ts))"
$WShell.sendkeys("{NUMLOCK}")
start-sleep -Seconds $rand
}
Echo "Keep alive with NUMLOCK"
$WShell = New-Object -com "WScript.shell"
while ($True)
{
$rand=Get-Random -Maximum 1800
$randminutes=$rand/60
$ts = New-TimeSpan -Seconds $rand
Write-Host "$([math]::Round($randminutes,2)) Minutes Start($(Get-Date)) End($((Get-Date)+$ts))"
$WShell.sendkeys("{NUMLOCK}")
start-sleep -Seconds $rand
}
Source: https://www.reddit.com/r/sysadmin/comments/th1me3/make_ms_teams_never_show_away_with_this/
Update Apr 2026 - Here is an improved script:
Clear-Host
Write-Host "Random keep-alive started. Press Ctrl+C to stop." -ForegroundColor Green
# Create WScript.Shell COM object once
$WShell = New-Object -ComObject WScript.Shell
# Configurable wait range (in seconds)
$MinWait = 60
$MaxWait = 180
Write-Host "Random keep-alive started. Press Ctrl+C to stop." -ForegroundColor Green
# Create WScript.Shell COM object once
$WShell = New-Object -ComObject WScript.Shell
# Configurable wait range (in seconds)
$MinWait = 60
$MaxWait = 180
# Choose which keys you want it to randomly press.
# Notes:
# - {SCROLLLOCK} and {NUMLOCK} toggle states (some people prefer these).
# - {F15} is usually harmless and doesn't toggle anything, but may not work everywhere.
# - Remove/add keys as you like.
$Keys = @(
"{SCROLLLOCK}",
"{NUMLOCK}",
"{F15}"
)
while ($true) {
# Random key press
$key = Get-Random -InputObject $Keys
$WShell.SendKeys($key)
# If you include lock keys and want them "pressed" but not left toggled,
# you can optionally press them twice to return to original state.
# Uncomment the next line if desired to press twice:
# $WShell.SendKeys($key)
# Random sleep between 1 and 3 minutes
$sleepSeconds = Get-Random -Minimum $MinWait -Maximum ($MaxWait + 1)
$timestamp = Get-Date -Format "HH:mm:ss"
Write-Host "[$timestamp] Sent $key | Sleeping $sleepSeconds seconds..." -ForegroundColor Cyan
Start-Sleep -Seconds $sleepSeconds
}
