Back to Blog
Guide

PowerShell Script to Keep Teams Active: F15, Num Lock and a Work-Hours Timer

A PowerShell script that presses F15 once a minute keeps Microsoft Teams Available, because Teams goes Away only after about 5 minutes with no input anywhere on the PC. Copy-ready scripts for PowerShell (F15, Num Lock, stop at a set time), Python and Mac, why SetThreadExecutionState does not work for Teams, and what the script cannot hide.

Slack Green Team
September 25, 2026
November 3, 2026
5 min read
Share:
microsoft teams
powershell
presence status
windows

A PowerShell script that presses F15 once a minute keeps Microsoft Teams Available. Teams switches you to Away after 5 minutes with no keyboard or mouse input anywhere on the computer: its own code, which we read on 3 November 2026, asks the computer for its idle time every 20 seconds and goes idle at 300,000 ms. F15 is a key no keyboard has, but Windows counts it as input, so the idle timer never reaches 5 minutes. The script needs no admin rights. Here it is, with a stop time so it ends with your work day:

# keep-teams-active.ps1 - presses F15 every 60 seconds until 17:30, Ctrl+C to stop
$shell = New-Object -ComObject WScript.Shell
$end = Get-Date '17:30'
while ((Get-Date) -lt $end) {
    $shell.SendKeys('{F15}')
    Start-Sleep -Seconds 60
}

A script that only blocks sleep, such as one calling SetThreadExecutionState, does not keep Teams green: it sends no input. Scripts that press a key or move the mouse help the Slack desktop app too, which counts input anywhere on the computer, while the PC is unlocked. Many people use both apps; see keep Teams and Slack active at the same time.

Why an F15 script keeps Teams Available

We fetched the Teams web client from teams.microsoft.com on 3 November 2026 and searched its code for the idle timer. These are the values it ships with:

// Microsoft Teams web client, fetched from teams.microsoft.com on 3 Nov 2026
_machineIdleThresholdMs=3e5          // 300,000 ms: idle after 5 minutes with no input on the computer
_machineIdlePollingIntervalMs=2e4    // asks the desktop host for the system idle time every 20 s
checkSystemIdleTime() -> getSystemIdleTime() -> handleSystemIdleTime(...)
getMachineLockState() === Locked     -> stop polling, Idle at once
appIdleTimeoutInMs: 3e5              // production config, same 5 minutes

So one key press a minute keeps the computer's idle time far below 5 minutes, and Teams sees it at its next 20-second check. The lock check comes before the idle check, which is why no script keeps a locked PC green.

Microsoft Learn, in User presence in Teams, says your presence becomes Away "if they're inactive for a few minutes or if the computer is locked", and Offline when the computer sleeps. Teams judges "inactive" from the computer's idle time, not from activity in the Teams window. Typing in Excel keeps you green. So does a scripted keypress. The timings are in how long before Teams shows you as Away.

Two things a script cannot beat:

  • • Locking the PC switches Teams to Away at once, script or not. If your screen locks after 5 idle minutes by policy, the keypresses also stop that lock, because they are input.
  • • Sleep switches Teams to Offline. Input keeps a PC from idle sleep, but closing the lid still sleeps it.
  • The PowerShell scripts

    Plain F15 loop

    The shortest version. It runs until you press Ctrl+C:

    # f15.ps1 - presses F15 once a minute until you press Ctrl+C
    $shell = New-Object -ComObject WScript.Shell
    while ($true) {
        $shell.SendKeys('{F15}')
        Start-Sleep -Seconds 60
    }

    This is the same loop as script 2 in keep a Windows PC awake with PowerShell. SendKeys sends the key to whatever window has focus. Most apps ignore F15, which is why it is the usual choice.

    Num Lock version

    Some scripts on Reddit and GitHub press Num Lock twice instead, so the key state ends where it started:

    # numlock.ps1 - toggles Num Lock off and on every 60 seconds
    $shell = New-Object -ComObject WScript.Shell
    while ($true) {
        $shell.SendKeys('{NUMLOCK}')
        Start-Sleep -Milliseconds 200
        $shell.SendKeys('{NUMLOCK}')
        Start-Sleep -Seconds 60
    }

    It works the same way for Teams. The Num Lock light on your keyboard flickers each minute, and if the script is stopped between the two presses, Num Lock stays off. F15 has neither problem. The same F15 trick on a Mac or Linux machine is in keyboard jiggler.

    Work-hours version

    The script at the top of this page stops at 17:30. To start later in the day and stop at a set time, check the clock on every loop:

    # keep-teams-active-hours.ps1 - presses F15 every 60 s between 09:00 and 17:30
    $shell = New-Object -ComObject WScript.Shell
    $start = [TimeSpan]'09:00'
    $stop  = [TimeSpan]'17:30'
    while ((Get-Date).TimeOfDay -lt $stop) {
        if ((Get-Date).TimeOfDay -ge $start) { $shell.SendKeys('{F15}') }
        Start-Sleep -Seconds 60
    }

    Change the two times to your own hours. After 17:30 the script ends by itself, and Teams goes Away about 5 minutes later.

    How to run a PowerShell script to keep Teams active

  • Paste the script into Notepad and save it as keep-teams-active.ps1.
  • Open PowerShell. No admin rights are needed. Go to the folder with cd.
  • Run it:
  • powershell -ExecutionPolicy Bypass -File .\keep-teams-active.ps1

  • Leave the window open, minimized if you like. Press Ctrl+C or close the window to stop it.

-ExecutionPolicy Bypass applies to this one run only and does not change a system setting. If your company blocks PowerShell through Group Policy or AppLocker, the script will not start, and you should not work around that. The settings-only options are in keep a work computer awake without admin rights.

Python and Mac scripts to keep Teams active

Python, on Windows or Mac. pyautogui can move the pointer one pixel and back once a minute:

# keep_teams_active.py - pip install pyautogui, then: python keep_teams_active.py
import time
import pyautogui

while True:
    pyautogui.moveRel(1, 0)
    pyautogui.moveRel(-1, 0)
    time.sleep(60)

Moving the pointer to a screen corner stops it (a pyautogui safety rule), and so does Ctrl+C. On a Mac, allow Terminal in System Settings, Privacy & Security, Accessibility first. Avoid pressing F15 on a Mac: on some Apple keyboards F14 and F15 change the screen brightness.

Mac, no Python. cliclick from Homebrew does the same from Terminal:

brew install cliclick
while true; do cliclick m:+1,+0 m:-1,+0; sleep 60; done

To also stop the Mac from sleeping, wrap it in caffeinate, which ships with macOS. More Mac options, including free jiggler apps, are in mouse jiggler for Mac. A Mac script that stops by itself after 8 hours is in how to keep Teams active on a Mac.

ScriptKeeps Teams greenKeeps PC awake
PowerShell F15YesYes
PowerShell Num Lock twiceYesYes
PowerShell SetThreadExecutionStateNoYes
powercfg timeouts set to 0NoYes, while plugged in
Python pyautogui nudgeYesYes
Mac cliclick loopYesWith caffeinate

Can your employer see a keep-Teams-active script?

Teams itself shows only the status: Available, not "Available because of a script". But the input is not invisible. Windows flags keys sent by SendKeys as injected input, and endpoint monitoring software can log that, along with the PowerShell process and its command line. A script that presses F15 at exactly 60-second intervals for eight hours is also an easy pattern to spot in activity data. What Teams reports to admins is in does Microsoft Teams track your activity, and detection of jigglers in general is in can a mouse jiggler be detected.

Teams has no setting that holds you at Available. The status Duration option works for Busy, Do not disturb and the others, but not for Available, so idle time still decides. The options that do not need a script are in how to keep your Teams status available.

Quick answers

Does it work in the new Teams app? Yes. New Teams reads the computer's idle time the same way.

Will the script keep my Teams mobile status green? No. The phone's Teams status depends on the app being on screen; see does Teams stay green on mobile.

Why does Teams still show Away with the script running? The PC locked, the lid closed, or the script window closed. Check that PowerShell is still running, and that nothing locks the screen by policy.

Related Articles

Guide

Does a Mouse Jiggler Work When the Computer Is Locked?

No. A mouse jiggler cannot unlock a computer or keep you active behind the lock screen, and Teams shows you Away the moment you lock. It works only if it runs before the lock kicks in, because the movement stops the idle timer that would lock the screen. What still works, what does not, and the locks a jiggler never stops.

Slack Green Team
Guide

What Does Presenting Mean in Teams? The Status and the Meeting Role

Presenting on Microsoft Teams is a status Teams sets while someone shares their screen, a window or PowerPoint Live slides in a meeting or call. It shows as a red circle with a white bar, mutes their notification banners, and ends when they stop sharing. It is different from the Presenter role in a meeting. What each means, how Presenting compares with In a meeting and Busy, and why it sometimes does not show.

Slack Green Team
Guide

How to Keep Teams Active (Green) on a Mac: What Works and What Does Not

Teams on a Mac turns Away after about 5 minutes with no keyboard or mouse input anywhere on the Mac, and at once when the screen locks. Lock Screen settings, caffeinate and Amphetamine stop the lock but not that timer, so Teams still goes yellow. A jiggler app, a one-line cliclick script or a USB jiggler creates input and keeps Teams Available. Setup for each.

Slack Green Team