Resources
What & Link | Type |
---|---|
List of AHK resources: awesome-AutoHotkey | List |
David Deley: AHK Expression Examples | Cheatsheet |
Common Gotchas and Issues
-
Options often use a single letter prefix before a "binding"
-
For example, controls that store the value of the control on submit into a variable, will accept the name of the variable prefixed by
v
.- So, if you want to store the result into
MyVar
, you would actually passvMyVar
.
- So, if you want to store the result into
-
Gui Controls also accept routines to be called via
g-label
- To call
MyFunc()
, you would usegMyFunc
- To call
-
-
Try to avoid calling
Click, Down
orSend {LButton down}
early - try to call it last in a given thread / routine- In my experience, AHK basically stopped execution of the current routine / thread until the an
Up
event was sent - either by my script or the user performing a mouse click. - I could not find any documentation that might explain this behavior
- In my experience, AHK basically stopped execution of the current routine / thread until the an
FAQ
-
Easiest way to debug
-
Add
OutputDebug
lines, and keep SysInternals DebugView open!
-
-
Why aren't my variables receiving updated values from the GUI controls?
-
Assuming you bound a variable, such as
MyVarName
to a GUI control, by using thevMyVarName
option, there could still be several reasons whyMyVarName
does not contain an up-to-date value-
You forgot to submit the GUI form
- Every time that you want to update your "bound" variables with fresh values from the GUI, you need to call
Gui, Submit
- To make things easier, you can create a wrapper function that calls Submit, such as
SubmitForm(){ Gui, Submit, NoHide}
, and then bind that function to be called on the control withgSubmitForm
.
- Every time that you want to update your "bound" variables with fresh values from the GUI, you need to call
-
The wrong syntax was used
- Remember
v
prefix - bind withvMyVarName
, notMyVarName
- Remember
-
There are multiple GUIs
- If you have multiple GUIs floating around, you have tell AHK which GUI you are trying to get fresh values for when submitting.
- If your GUI is named
MainForm
, you would get fresh values by first calling:Gui, MainForm:Submit
-
-
-
How to refer to named GUIs?
- Add
name:
before the subcommand - Example: change
Gui, Show
toGui, MyGui:Show
- Add
-
How to package as an EXE
- Use right click and
"compile script"
option, or dedicated compiler program (%ProgramFiles%\AutoHotkey\Compiler\Ahk2Exe.exe
) - Dedicated program will let you customize icon - see https://autohotkey.com/board/topic/58205-change-icon-of-compiled-ahk-script/
- Use right click and
-
How to detect mouse movement
-
You can't - best way is to just use a timer and compare last coords with current to see if changed
-
-
SetTimer issues
-
Using a function
- You can use a function instead of a label - just pass it as second arg
-
Using variable MS
- pass with % in front
-
-
GetMousePos returns bad results (relative positions)
- By default, coordinates are relative to your UI, not the total screen. See this for the different coordinate options.
- Use
CoordMode, mouse, Screen
for coordinates that are relative to the desktop (entire screen)
FAQ Continued - GUI Controls Specific
-
How to pass both range and default to slider?
- the default value HAS to come LAST - otherwise it is ignored - and must be integer
- e.g. `Gui, Add, Slider, vMySliderVal, Range1-50 ... 25
- If you want to use a variable as the slider default, remember to prefix with % - e.g.
- Here is a full example:
Gui, MainWin:Add, Slider, vRemoteControlLagMs gGetConfigFromUi +Range0-%Slider_Max%, % RemoteControlLagMs
-
How the heck do you pass a control Id?
-
The docs really gloss over this, but the
v__
option actually is dual-purpose; both the variable to store value into, AND the control Id
-