
π This article includes 1 downloadable practice file β
In this article
Scripts become more useful when they can ask a question and react. AHK v2 has proper variables and expressions, plus simple dialog boxes.
Variables and expressions
amt := 2500
gst := Round(amt * 0.18, 2)
MsgBox "GST is " gst ; text and variables joined by a space
Ask for input
ib := InputBox("Amount (Rs):", "GST calculator")
if ib.Result = "OK" && IsNumber(ib.Value)
MsgBox "Total: " Number(ib.Value) * 1.18
Yes/No questions
if MsgBox("Copy the total?", "GST", "YesNo") = "Yes" runs code only when the user agrees.
The clipboard
A_Clipboard holds copied text: read it, change it (StrUpper, StrReplace, Trim) and paste it back. Great for cleaning copied text before pasting into forms.
Where people go wrong
| Problem | Cause |
|---|---|
| “2500” + 1 gives odd results | Convert with Number() |
| Using = to assign | v2 uses := to assign |
Practice
Run the script and press Ctrl+Alt+G; then copy some text and press Ctrl+Alt+U in Notepad.
π Practice files for this article
- β¨οΈLesson 5 script (AutoHotkey v2)Double-click to run after installing AutoHotkey v2.β¬ AHK Β· 549 B
Free to use for learning. Files with macros (.bas) are plain text β import them with Alt+F11 β File β Import File, and always test on a copy.
Stuck on a step? Ask a question and the AI answers using this article.