Back to Blog
Guide

AutoHotkey Script to Keep Your Computer Awake (v2 Code)

Three AutoHotkey v2 scripts that keep a Windows PC awake: one calls SetThreadExecutionState and sends no input, one presses F15 after 4 idle minutes so Teams stays green, and one nudges the mouse by a pixel. How to run them, start them with Windows, and what they do not fix.

Slack Green Team
September 27, 2026
November 3, 2026
4 min read
Share:
autohotkey
windows
keep awake
scripts

Reading on your phone?

Run the idle test on your computer

Slack sets you away on your computer, so this free test runs there. Send yourself this page and press Start at your desk.

The shortest AutoHotkey script to keep a Windows computer awake is a few lines of AutoHotkey v2: it calls the Windows function SetThreadExecutionState with the flags for "system required" and "display required", then stays running. Windows will not sleep or turn off the screen until you exit the script, and it sends no keystrokes or mouse moves. If you also need Microsoft Teams to stay green, use the second script below, which presses the unused F15 key after 4 minutes without input. A third script nudges the mouse by one pixel instead. If the goal is Slack rather than Teams, Slack Green keeps your dot green from a server with the computer asleep or shut, so no script has to run, free for 7 days with no card.

The scripts that send a key or move the mouse keep the Slack desktop app active too, whatever window is in focus (Slack desktop 4.52.178 code, checked 7 Oct 2026); the ones that only block sleep do not.

AutoHotkey script to keep your computer awake: SetThreadExecutionState, F15 when idle, 1-pixel mouse nudge

Script 1: block sleep with no input

#Requires AutoHotkey v2.0
#SingleInstance Force
; ES_CONTINUOUS (0x80000000) | ES_DISPLAY_REQUIRED (0x2) | ES_SYSTEM_REQUIRED (0x1)
DllCall("SetThreadExecutionState", "UInt", 0x80000003)
Persistent

SetThreadExecutionState is the Windows API that video players and presentation apps use to stop sleep. ES_CONTINUOUS keeps the request in force until the script ends, so Windows goes back to its normal sleep settings the moment you exit. Persistent keeps a script with no hotkeys or timers running.

To keep the PC awake but let the screen turn off, use 0x80000001 instead of 0x80000003.

This script does not reset the idle timer. Apps that watch for input, such as Teams, still set you Away after about 5 minutes, and a lock-screen policy set by your IT department still locks the screen on time.

Script 2: press F15 when idle, for Teams

#Requires AutoHotkey v2.0
#SingleInstance Force
SetTimer(Nudge, 60000)          ; check once a minute

Nudge() {
    if (A_TimeIdle > 240000)    ; 4 minutes with no keyboard or mouse input
        Send("{F15}")
}

Most keyboards have no F15 key, so no app reacts to it, but Windows counts it as input and resets the idle timer. The script only presses it after 4 minutes without input, so it stays out of the way while you work. Teams reads the Windows idle time and sets you Away after about 5 minutes, so this keeps Teams green; the timing is in how long before Teams shows away. The Caffeine app for Windows uses the same F15 trick; see Caffeine app for Windows.

At best, an AutoHotkey script that sends a key keeps Slack active while the PC is awake and unlocked. Once the PC locks or sleeps, or the lid closes, Slack sets you away. A server-side tool keeps your Slack dot green with no input, even while the laptop sleeps or the lid is closed.

Script 3: nudge the mouse, a mouse jiggler in AutoHotkey

#Requires AutoHotkey v2.0
#SingleInstance Force
SetTimer(Jiggle, 60000)

Jiggle() {
    if (A_TimeIdle > 240000) {
        MouseMove(1, 0, 0, "R")    ; one pixel right
        MouseMove(-1, 0, 0, "R")   ; and back
    }
}

"R" makes the move relative to where the pointer is, and speed 0 moves it instantly. The pointer ends where it started. Use this if a program ignores key presses but reacts to mouse movement. How the one-pixel approach compares with USB and mechanical jigglers is in DIY mouse jiggler.

ScriptStops sleepKeeps Teams greenKeeps Slack active
1. SetThreadExecutionStateYesNoNo
2. F15 when idleYesYesShould, desktop app, while unlocked
3. Mouse nudge when idleYesYesShould, desktop app, while unlocked

How to run the script and start it with Windows

Run a keep-awake script: install AutoHotkey v2, save keepawake.ahk, double-click, stop from the tray icon

  • Install AutoHotkey v2 from autohotkey.com. The installer can install for your user only, which needs no admin rights on most PCs.
  • Save one of the scripts as keepawake.ahk in Notepad (choose All files as the type so it does not end in .txt).
  • Double-click the file. A green H icon appears in the system tray while it runs.
  • To stop it, right-click the H icon and choose Exit.
  • To start it with Windows, press Win+R, type shell:startup, press Enter, and put a shortcut to keepawake.ahk in the folder that opens.

    The scripts use v2 syntax. AutoHotkey v1 is no longer developed, and v1 scripts such as Send, {F15} will not run under v2 without changes.

    If you cannot install AutoHotkey

    Many work PCs block unknown software. Two options need nothing extra installed:

  • • PowerShell. The same SetThreadExecutionState call and an F15 loop work in a PowerShell script; see keep a computer awake with PowerShell.
  • • Microsoft PowerToys Awake, if PowerToys is allowed; see PowerToys Awake and Slack.

More options for locked-down PCs are in keep a work computer awake without admin rights.

Is an AutoHotkey keep-awake script visible to IT?

Yes, to anyone who looks. AutoHotkey runs as a normal process (AutoHotkey64.exe) with your script's path on its command line, and endpoint tools such as Microsoft Defender, Intune and CrowdStrike record processes. Scripts 2 and 3 create input that Windows marks as injected, which some monitoring tools can check. What each tool sees is in can CrowdStrike detect a mouse jiggler and how to detect a mouse jiggler.

FAQ

What is the AutoHotkey script to prevent sleep? DllCall("SetThreadExecutionState", "UInt", 0x80000003) followed by Persistent, in AutoHotkey v2. It blocks sleep and screen-off until you exit.

How do I make an AutoHotkey mouse jiggler? Use a timer that runs MouseMove(1, 0, 0, "R") and MouseMove(-1, 0, 0, "R") when A_TimeIdle is over a few minutes, as in script 3.

Does an AutoHotkey script keep Teams active? Yes, if it creates input. Script 2 (F15) and script 3 (mouse nudge) reset the Windows idle timer that Teams reads. Script 1 does not.

Does an AutoHotkey script keep Slack active? It should keep the Slack desktop app active while the PC is awake and unlocked; we have not timed it on Windows. The Slack desktop app counts keyboard and mouse input anywhere on the computer (Slack desktop 4.52.178 code, checked 7 Oct 2026).

Does an AutoHotkey script work when the PC is locked? Script 1 still blocks sleep. Teams shows Away as soon as the PC is locked, whatever the script does.

Related Articles

Guide

PowerToys Awake Managed by Your Organization: What It Means

PowerToys shows 'This setting is managed by your organization' when your IT team set a group policy for Awake. A value of 0 forces Awake off and greys out the toggle; 1 forces it on. How to see which policy applies with one reg query, why Awake exits when started from the command line, and what you can still do.

Slack Green Team
Guide

How to Keep a Remote Desktop Session Active and Stop Idle Disconnects

Remote Desktop sessions end for four reasons: an idle time limit set by policy, a network device that drops quiet connections, a lock screen on the remote PC, and a minimized window that stops drawing. The setting, registry value and PowerShell line for each.

Slack Green Team
Guide

Move Mouse App: Download, Settings and Alternatives

Move Mouse is a free, open-source Windows app by Steve Williams that moves, clicks or scrolls on a timer so your PC does not lock or sleep. Get it from the Microsoft Store or GitHub, not from look-alike download sites. It keeps Microsoft Teams and the Slack desktop app green while the PC is unlocked. Settings, why it stops working, and alternatives for Mac.

Slack Green Team