AutoHotkey Tip of the Week: Toggling Features On and Off

While You’ll Find AutoHotkey Offers Many Methods for Turning Things On and Off, This Technique Makes It Easy

ToDoListINIOver the years I’ve used a number of different approaches to changing the state of buttons, checkmarks, and various other aspects of AutoHotkey app. But, as recommended by numerous sources, I prefer a simple variable reset to the opposite state (on/true/1 or off/false/0). The code comes in shorthand form using the logical-not (!) operator:

Toggle := !Toggle

When used in an expression, this form for the logical-not (!) operator switches off to on and on to off. 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.

ToDoListINI
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

AutoHotkey Tip of the Week: Increase the Flexibility of Menus by Passing Data with the BoundFunc Object

Streamline and Add Power to Hotstring Menus by Binding Action Parameters Directly to Each Menu Item

*          *          *

If you use AutoHotkey menus, then you may find this blog the most useful menu tip yet. At first, using the BoundFunc Object to pass data may seem confusing, but, once understood, it opens up many more opportunities for taking advantage of menus in your AutoHotkey scripts.

*          *          *

HotstringSubMenus

As often happens when working on an AutoHotkey script, a deeper understanding of the available tools completely changes the direction of the project. While all of the Menu tricks I’ve offered in the past HotstringMenu.ahk scripts still work (and you may want to continue using many of those techniques), the following approach which combines arrays, the variadic function parameter, and the boundfunc object creates a cleaner, more functional structure for generating Hotstring replacement menus. In short, implementing the boundfunc object allows me to drop many of those previous menu tricks and build menus using virtually any menu item format without regard for their later use through the value of the A_ThisMenuItem variable.

Continue reading

AutoHotkey Tip of the Week: Fold Long AutoHotkey Menus into Columns

Sometimes We Resort to Programming Trickery to Make Autohotkey Menus Look Better

The Windows Menu control is part of the Windows operating system. AutoHotkey offers you the Menu command for setting up and altering custom menus using this built-in control. However, much of the inflexibility of AutoHotkey menus results from the limitations of the Windows Menu object itself. This rigidity often forces us to resort to programming sleight-of-hand to accomplish many goals. Continue reading

AutoHotkey Tip of the Week: Flexible AutoHotkey Hotstring Menus Using Arrays

New Parameters for the HotstringMenu() Function Adds Flexibility and Power to Pop-up Menus

In my last blog, I started looking at adding the variadic parameter (accepts multiple inputs) and a Menu subroutine parameter to the HotstringMenu() function. While in the process of creating alternative Label subroutines, I found that changing a subroutine often called for a new menu-creating function. Rather than resorting to multiple functions, I decided to add one more parameter for tailoring the master function.

CoverImage200
A Multitude of AutoHotkey Tips and Tricks

Note: This blog discusses the use of AutoHotkey object-based arrays (simple and associative) with the function’s variadic parameter. A review of my books demonstrated that most included discussions of arrays (pseudo-arrays and object-based arrays). In particular,  Chapter 12.1.5 “Using Associative Arrays to Solve the Instant Hotkey Data Recall Problem” in the book Jack’s Motley Assortment of AutoHotkey Tips explains the difference between the various array types while offering a practical example of an associative array.

Continue reading

AutoHotkey Tip of the Week: Use the Variadic Function Parameter for an Unknown Number of Values in Hotstring Menus

What To Do When You Don’t Know How Many Values You Will Use? For Hotstring Menus, the Variadic Function Parameter Allows a Variable Number of Arguments or Direct Array Input

Variadic Function: One which accepts a variable number of arguments.

MenuEmojiTagsLight Bulb!In the blog, “AutoHotkey Tip of the Week: Hotstring Menu Techniques for Inserting Symbols and Emojis“, I discussed switching from the deprecated StringSplit command to  StrSplit() function before posting the scriptAfter posting my new HotstringMenu.ahk script on the AutoHotkey forum, I received the following comment from the user Delta Pythagorean. I have mixed feelings about the recommended changes:

You can simplify this down by making the parameter variadic and letting the user chose which label to set the menu to work off of.

:x:brb::HotStringMenu("MenuLabel","Hello",,"Goodbye","See you later!")

MenuLabel:
  MsgBox, % "You said: " A_ThisMenuItem
Return

HotstringMenu(Handle, TextList*) {
  For Each, Item in TextList
    Menu, MyMenu, Add, % Item, % (Item != "") ? Handle : ""
  Menu, MyMenu, Show
  Menu, MyMenu, DeleteAll
}

I like the overall concept. This change to the HotstringMenu() function expands its capabilities by adding a selectable subroutine Label name and uses a variadic parameter which allows the functions to accept an unknown number of values. Continue reading

AutoHotkey Tip of the Week: Hotstring Menu Techniques for Inserting Symbols and Emojis

Place Special Characters and Emojis in Hotstring Menus to Make Them Easy to Find for Inserting into Documents, Plus Sample Hotstring Special Character Menus

MenuEmoji
Hotstring Menu

In my last blog, “AutoHotkey Hotstring Menus for Text Replacement Options“, I expanded upon the Hotstring menu technique discussed in Chapters Eight and Nine of my book Beginning AutoHotkey Hotstrings. While the menus work great, I noticed that, in many instances, the standard built-in Windows menu objects do not always make it easy to distinguish various characters. For example, when I placed a mix of symbols and emojis in a menu, it produced ambiguous results:

:x*?:b``::TextMenu("🦄,🐀,🐁,🐂,🐃,®,❓,❔")

The characters appear small in the menu (shown at right above)—often without clearly defined differences.

In the menu, the rat (🐀) and mouse (🐁) seem very similar—as do the ox (🐂) and the water buffalo (🐃). The two question marks at the end of the menu look identical, although, the first emoji inserts the punctuation mark in red (❓) while the second adds a white question mark (❔). We need another method for discriminating between the menu options. Continue reading

AutoHotkey Tip of the Week: AutoHotkey Hotstring Menus for Text Replacement Options

Put Hard-to-Remember AutoHotkey Hotstring Replacements in a Menu

Beginning AutoHotkey Hotstrings 200px

Light Bulb!

This tip expands on Chapter Eight of my book Beginning AutoHotkey Hotstrings, “Make Your Own Text AutoCorrect Hotstring Pop-up Menus with AutoHotkey” and Chapter Nine, “How to Turn AutoHotkey Hotstring AutoCorrect Pop-up Menus into a Function.” You can use these techniques in your AutoHotkey scripts to make the selection of similar Hotstrings easier to remember by selecting from a menu. Continue reading

AutoHotkey Tip of the Week: Quick and Dirty Printing—September 30, 2019

If You Need a Hardcopy, Then You Can Use this AutoHotkey Print Technique—Plus a Cheap Way to Get Printer Ink

Library Benefits

Every once in a while you want to put something on paper. Most often, you open the appropriate program (i.e. a text editor or word processor for text documents, PDF viewer for PDFs, or graphics program for images) and print from that application. Trying to use AutoHotkey for direct printing can get pretty complicated (as discussed in Section 10.1.1 “Printing with AutoHotkey Made Simple” of the book Jack’s Motley Assortment of AutoHotkey Tips). But, for a quick printout, you can write an AutoHotkey line of code which sends a document to the printer from a program—without first opening the app.

Continue reading

AutoHotkey Tip of the Week: Add Single-Key Shortcuts to Pop-up Menus—September 16, 2019

Sometimes It’s Just Easier to Use the Keyboard Rather Than Your Mouse

HotString Pop-upIf a menu busts in while typing, it forces you to switch to your mouse for resolution. This can get pretty annoying if your script uses a number of pop-up menus. For example, Chapter Eight, “Make Your Own Text AutoCorrect Hotstring Pop-up Menus with AutoHotkey” and Chapter Nine, “How to Turn AutoHotkey Hotstring AutoCorrect Pop-up Menus into a Function” of the book Beginning AutoHotkey Hotstrings shows you how to set up a list of alternative corrections. It works well for offering options but, at times, wouldn’t you prefer to hit a single key to make the selection rather than first fetching the mouse, then clicking?

Recent Question from a Reader:

Is there any way to improve the script in order to, once the menu appears, select an option using a given key combination?

For instance: If I typed “alt+1” AutoHotkey would automatically select the option “again”, if I typed “alt+2” it would select the option “a gin” and so on so forth until alt+0?

*          *          *
Continue reading