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?”
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.
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 →