Joshua's Cheatsheets - AutoHotkey - Resources, FAQs, Tips, Etc.
Light
help

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 pass vMyVar.
    • Gui Controls also accept routines to be called via g-label

      • To call MyFunc(), you would use gMyFunc
  • Try to avoid calling Click, Down or Send {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

FAQ

  • Easiest way to debug

  • 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 the vMyVarName option, there could still be several reasons why MyVarName 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 with gSubmitForm.
      • The wrong syntax was used

        • Remember v prefix - bind with vMyVarName, not MyVarName
      • 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 to Gui, MyGui:Show
  • How to package as an EXE

  • How to detect mouse movement

  • 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?

Markdown Source Last Updated:
Wed Mar 25 2020 23:45:17 GMT+0000 (Coordinated Universal Time)
Markdown Source Created:
Wed Mar 25 2020 21:16:07 GMT+0000 (Coordinated Universal Time)
© 2020 Joshua Tzucker, Built with Gatsby