Built-in Variables and Functions
Remarks#
AutoHotkey comes with many built-in functions and variables which can be used anywhere inside a script.
For a full list including explanations, see:
Determining the User Idle Time
if(A_TimeIdlePhysical > 60000) { ; 60,000 milliseconds
WinClose, ahk_class Chrome_WidgetWin_1
MsgBox, Google Chrome was closed due to user inactivity.
}
This check could be done periodically, e.g. using SetTimer
.
Auto-insert current weekday’s name
This example inserts/sends the current day of the week’s full name (e.g. Sunday) whenever Ctrl + Alt + D is pressed:
^!d::Send, %A_DDDD%
Extract string parts using RegEx
myDebt := 9000
index := RegExMatch("You owe me $42", "\$(\d+)", dollars)
if(index > 0) { ; indices are usually 1-based in AHK
myDebt += dollars1
MsgBox, Current debt: %myDebt%
}
Result:
Current debt: 9042
Trim a string
myString := " hello, Trim()! "
trimmed := Trim(myString)
FileAppend, % trimmed "`n", TrimmedStrings.txt
Note that Trim()
will not manipulate the original string, but return a new one which should be stored or output somewhere.