Use the GoTo Command to Traverse Long Subroutines (Part Four: Finishing AutoHotkey GUI Scripts)

Sometimes the GoTo Command Makes Life Easier without Creating Perverse Effects

This next portion of the InstantHotstring.ahk menubar implementation did not go as I had expected. I thought that I would break up the routine launched by the Save Hotstrings button into separate subroutines or functions, then call each as appropriate for the corresponding Save/Append Hotstrings menu items (as seen in the image). I didn’t look forward to it because I knew it could get a little confusing. Some items would require multiple subroutine calls while others would need to just run—depending upon the menu selections made by the user.

I didn’t want to write redundant subroutines, but separating the various features of the complete routine required more than merely adding Return commands to encapsulate the code. I finally ask myself, “Why not insert AutoHotkey Labels into the main Save routine and use the GoTo command to jump my way through the decision points?”

Continue reading

AutoHotkey Tip of the Week: Use the GUI Menu Bar for Instant Hotkeys

Rather than Creating New Hotkeys and Isolating Them Using the #IfWinActive Directive, Simply Add Keyboard Accelerators Using a GUI Menu Bar

Note: This week’s keyboard accelerator tip is not the same technique as adding an ampersand before any letter in a menu item—although that trick still works. The beauty of this technique lies in the fact that you can embed and execute a multitude of active window Hotkey-like actions in a menu bar without ever opening the menu itself.

In almost every one of my books, I discuss using the Menu command to build free-floating selection lists for a wide variety of tasks. I use menus for the HotstringMenu.ahk script, the QuickLinks.ahk favorites app, SynomynLookup.ahk, and numerous other purposes. In the GUI ListView control examples found in the AutoHotkey Applications book for the to-do list, the address book, the calorie counting app and listings of icon images, the right-click context menu pops open for individual action items. Menus provide an easy method for adding features to AutoHotkey scripts while saving space. I’ve always known that you can add a menu bar to the top of any AutoHotkey GUI (Graphical User Interface) but had little to say about it—until now.

The Ctrl+T in the menu bar item creates an accelerator key combination which, whenever pressed, acts as an active window Hotkey for instantly executing the option—even without opening the GUI menu bar.

While working on my latest to-do list script (ToDoListINI.ahk), I realized that I wanted to add a couple more options to the app, but I didn’t like the idea of inserting more buttons into the GUI. I naturally turned to a menu bar at the top of the GUI which could include many more actions while taking up minimal area. After a quick glance at the Gui, Menu command, I realized that I had routinely overlooked one of the most important aspects of Gui menu bars: accelerator keyboard combinations. Continue reading