AutoHotkey Tip of the Week: Quick Menu for Activating Open Windows

With a Few Modifications, the WindowList.ahk Script Pops Up a Menu of Open Windows for Quick Activation—Plus, How to Detect When a Windows Opens or Closes

I originally used the WindowList.ahk script as a demonstration of how to use the GUI DropDownList control as a list of selection options for activating open windows (included in the Digging Deeper Into AutoHotkey book). Once, while testing someone’s script, it proved very useful. I could not find the GUI window generated by the code. The script had placed the target window somewhere off the screen. The scriptwriter originally used a second monitor—which I didn’t have. The WindowList.ahk script moved the window back into my view.

As I reviewed the script, I realized that building a pop-up menu of open windows could serve a purpose similar to the QuickLinks.ahk script—except, rather than launching apps and Web sites, the menu would activate open windows. Now, that’s something that I can use!

I often keep numerous windows open simultaneously. Generally, I locate a window by hovering over the Windows Taskbar then selecting the image which looks right. It takes a second for the thumbnails to appear, then hovering over each helps me make my selection. But what if I could maintain a menu of all open Windows available in a menu for instant activation? Continue reading

AutoHotkey Tip of the Week: Windows Trick for Adding Embedded Folder Icons to QuickLinks Menus

This Technique Accesses Icons Embedded in Windows Folders for Inserting into Pop-up Menus—Plus, the New Combined Switch/Case Statement QuickLinks QL_GetIcon() Function

I completely rewrote the functions from the last blog for adding icons to the menus in the QuickLinks.ahk script combining the two into a shorter prioritized list using Switch/Case statements. In the process—after investigating how to read icons embedded in Windows folder/directory listings—I discovered an interesting Windows secret. It turns out that this procedure requires a totally different Windows maneuver than that used for reading Windows Shortcut file icons.

The Windows Desktop.ini File

UnHideFiles
Ryan’s UnHideFiles.ahk script makes Windows Registry changes to hide and unhide files.

When you embed an icon into a Windows folder (right-click on the folder name in Windows File Explorer, select Properties and the Customize tap, then click Change Icon… and browse for icons), rather than saving the icon path and icon number in the folder itself—as Windows does for shortcut files—it creates a special hidden file named desktop.ini in that same folder. With Windows set to Show Hidden Files, folder and drives in the View tab of the Folder Options window, you can view the hidden desktop.ini file in that folder. (Tip: You can use Ryan’s UnHideFiles.ahk script to hide and unhide files and folders.) Continue reading

AutoHotkey Tip of the Week: Add Dynamic Submenus to Static Menus Using Menu, DeleteAll

How to Add an Updating Dynamic Submenu to a Static AutoHotkey MenuUnderstanding the Difference Between Menu, DeleteAll Command and Menu, Delete Command

When I first wrote the HotstringMenu.ahk script, I planned it as a substitution for ambiguous or multiple option Hotstring text replacements. After typing one of the activation strings, a menu of alternative replacements pops-up. Since the Hotstring menus include many varied item lists, it made sense to create each only when needed. However, when I decided to combine a number of these menus into a group under one main menu, preloading the numerous static submenus seemed more practical. That left me with one problem. Some menus, such as current time and date insertion, need updating each time they pop up.

HotstringTimeDateMenu
The TimeDate submenu updates each time the top-level menu displays.

Once created, AutoHotkey menus sit idle as static tools waiting for the Menu, Show command—at least until deleted. While each subroutine called by a clicked menu item can produce variable results, the contents of the menu itself remain fixed. (Menu items do not accept variables as item names.) That means scripts which use the MenuItemName variable as dynamic output won’t update—unless the script deletes the menu items, then recreates them. If used as a submenu, the DateMenus.ahk script for inserting various current time and/or date formats into documents needs such an active menu. Continue reading

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