Skip to content

Instantly share code, notes, and snippets.

@andrewsuzuki
Created January 22, 2020 00:54
Show Gist options
  • Save andrewsuzuki/76235480227579bf277afc89c0dc1d06 to your computer and use it in GitHub Desktop.
Save andrewsuzuki/76235480227579bf277afc89c0dc1d06 to your computer and use it in GitHub Desktop.
AutoIt script for activating (focusing) a window automatically after an idle timeout (no mouse/keyboard interaction)
; Activate window after idle timeout
; Script for AutoIt (Windows)
; by Andrew Suzuki
#include <WinAPISys.au3>
$title = "YOUR WINDOW TITLE HERE"
$minutes = 2 ; every two minutes
$sleepTimeMillis = 5*1000 ; check every 5 seconds
; Match any substring in title
AutoItSetOption("WinTitleMatchMode", 2)
While 1
; If the idle timer is more than $minutes...
If _WinAPI_GetIdleTime() >= $minutes * 60 * 1000 Then
; Attempt to activate window
If Not (WinActivate($title)) Then
; Matching window not found
; Do what you want here (exec, msgbox error, etc)
EndIf
EndIf
; Sleep for $sleepTimeMillis before looping again
Sleep($sleepTimeMillis)
WEnd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment