Keep PC Awake Script (Anti-AFK)

Runs in your browserDeveloper Tools#Productivity#Windows

Create a Windows script that keeps your PC awake and the screen on for a set time, with clear stop steps.

Method

Asks Windows not to sleep or turn off the screen while the script runs. Nothing is typed or clicked.

No script needed? Microsoft PowerToys has Awake, which does the same from the system tray. Or set sleep to Never in Settings > System > Power.

Check your workplace rules first: some employers don't allow tools that keep a PC awake or simulate activity, and security software may block scripts.

KeepAwake.ps1

# Keep PC Awake - made with ToolKit360
# Stops Windows from sleeping and turning off the screen while this window is open, for 2 hours.
# It asks Windows directly (SetThreadExecutionState); it does not press keys or move the mouse.
#
# How to run:  right-click this file > Run with PowerShell (Windows 11: Show more options first).
# How to stop: close this window or press Ctrl+C. Normal sleep settings return straight away.

$minutes = 120   # how long to keep awake; 0 = until you close this window

Add-Type -Namespace ToolKit360 -Name Power -MemberDefinition '[DllImport("kernel32.dll")] public static extern uint SetThreadExecutionState(uint esFlags);'

# ES_CONTINUOUS (0x80000000) + ES_SYSTEM_REQUIRED (0x1) + ES_DISPLAY_REQUIRED (0x2)
$keepAwake = [uint32]2147483651
$normal = [uint32]2147483648

$Host.UI.RawUI.WindowTitle = 'Keep PC Awake - close this window to stop'
if ($minutes -gt 0) { $end = (Get-Date).AddMinutes($minutes) } else { $end = [datetime]::MaxValue }

try {
    if ($minutes -gt 0) {
        Write-Host ("Keeping this PC awake until {0:HH:mm}. Close this window to stop sooner." -f $end)
    } else {
        Write-Host 'Keeping this PC awake. Close this window or press Ctrl+C to stop.'
    }
    while ((Get-Date) -lt $end) {
        [void][ToolKit360.Power]::SetThreadExecutionState($keepAwake)
        Start-Sleep -Seconds 30
    }
} finally {
    [void][ToolKit360.Power]::SetThreadExecutionState($normal)
    Write-Host 'Stopped. Windows is back to its normal sleep settings.'
}
How to run
Right-click KeepAwake.ps1 and choose Run with PowerShell (on Windows 11, Show more options first). Double-clicking only opens it in Notepad. If Windows says running scripts is disabled, open PowerShell in that folder and run: powershell -ExecutionPolicy Bypass -File .\KeepAwake.ps1
How to stop
Close the PowerShell window or press Ctrl+C in it. Windows goes back to its normal sleep settings straight away.
How to use, limits & privacy

About Keep PC Awake Script (Anti-AFK)

Create a small Windows script that stops your PC from sleeping or turning off the screen for as long as you choose, for example during a long download, render, backup or presentation. The recommended script asks Windows directly (SetThreadExecutionState) and presses no keys. An optional script presses the unused F15 key every few minutes for programs that only count keyboard activity. Each script shows how to run it and how to stop it.

How to Use

1

Choose the method and time

Keep Stop sleep (recommended), choose how long it should run and whether the screen stays on. Choose Key press every few minutes only if a program needs keyboard activity.

2

Download the script

Click Download to save KeepAwake.ps1 (or KeyPress.ps1 / KeyPress.vbs), or copy the code into a file yourself.

3

Run it

Right-click the .ps1 file and choose Run with PowerShell (on Windows 11, Show more options first). Double-clicking a .ps1 file only opens it in Notepad.

4

Stop it

Close the PowerShell window or press Ctrl+C. A .vbs script has no window: end Microsoft Windows Based Script Host in Task Manager.

Privacy & Processing

  • Mode: local
  • Files Leave Browser: Local tool processing; review details below
  • Max Input Size: Device memory limits
  • Account Required: No
  • Data Stored Locally: Nothing is saved; reloading the page resets the options.
  • Network Processing: Assets or models may require an initial download

The script is built in your browser. Nothing is uploaded, and the scripts make no network connections.

Rules & Limitations

  • Windows 10 and 11 only. Nothing starts with Windows: run the script each time you need it.
  • If Windows says running scripts is disabled, run powershell -ExecutionPolicy Bypass -File .\KeepAwake.ps1 in that folder. Work PCs may block scripts completely.
  • The key-press script sends F15 to whichever window is in front. VBScript is being phased out of Windows 11, so prefer the .ps1 version.
  • Your organisation may not allow tools that keep a PC awake or simulate activity, and antivirus software may flag scripts. Check before you use one at work.
  • Closing the laptop lid or pressing the power button can still put the PC to sleep, depending on Windows power settings.

Top Suggestions

  • Keeping a large download or upload running overnight
  • Stopping the screen turning off during a presentation or video call
  • Letting a long video render, backup or game update finish
  • Keeping a remote desktop session from timing out for a set time

Keep PC Awake Script (Anti-AFK) FAQ

How do I stop my Windows PC from going to sleep?

Download the Stop sleep script, right-click it and choose Run with PowerShell. While its window is open Windows won't sleep; close the window to go back to normal. For a permanent change, set sleep to Never in Settings > System > Power.

Is there a way without a script?

Yes. Microsoft PowerToys includes Awake, which keeps the PC awake from an icon in the system tray, and Windows Settings lets you set screen and sleep timeouts to Never.

Why does my .ps1 file open in Notepad?

Windows opens PowerShell scripts in an editor on double-click to stop them running by accident. Right-click the file and choose Run with PowerShell instead.

What is the difference between the two methods?

Stop sleep tells Windows not to sleep or dim the screen, the same way video players do, and types nothing. The key-press method sends F15 so programs that watch for keyboard input see activity; use it only when a program needs that.

Is this the same as a mouse jiggler?

The key-press script works like the Caffeine app, pressing an unused key instead of moving the mouse. The recommended Stop sleep script is different: it only keeps Windows awake and does not fake any input.

Does the script send any data?

No. The scripts only call Windows on your own PC; they make no network connections and change no settings permanently. This page builds them in your browser.