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: Add Temporary Hotkeys to MsgBox Windows—September 23, 2019

Isolate Hotkeys to Only Operate for an Open or Active Window

In the Weekly Tip, “IfWinActive Versus #IfWinActive“, I recommended isolating Hotkeys to specific windows. This time I offer a practical example.

hotkeycover200For more information, see “Chapter Two: Block Windows Shortcuts with AutoHotkey” and “Chapter Three: AutoHotkey #Directives for Context-Sensitive Hotkeys—#IfWinActive” of the book AutoHotkey Hotkey Tips, Tricks, and Techniques.

The #IfWinExist directive offers a number of advantages when creating temporary Hotkeys:

  1. The Hotkeys activate only when AutoHotkey opens the controlling window.
  2. If other conflicting Hotkeys exist, the temporary Hotkeys take precedence as long as the window exists.
  3. After closing the controlling window, the Hotkeys deactivate minimizing interference with other possible Hotkeys or shortcuts.

Continue reading

AutoHotkey Tip of the Week: Auto-Swap Transposed Letters—September 9, 2019

Tip: Fix Reversed Letter Typos with this Simple Hotkey Trick

SwapLetters
Place the cursor between two letters and hit the Alt+R Hotkey combination. The letters reverse positions.

Light Bulb!I use this Hotkey whenever my mild dyslexia kicks in and leaves me with swapped letters. My AutoHotkey AutoCorrect.ahk script may catch many such errors but many more make it on to my computer screen. I could have written a Hotkey routine which swapped pre-selected (highlighted) letters, but, rather than taking the time to select the characters by dragging the mouse across them, I wanted to merely place the cursor between the two errant letters.

This use of the Send command makes it incredibly easy to transpose any two letters. Simply place the cursor between them and hit ALT+R (as shown in the figure.)

Continue reading

Pressing GUI Buttons with a Single Keystroke (AutoHotkey Tip)

Sometimes We Find It Easier to Hit a Key Rather Than Click a Button

An AutoHotkey forum user posted a question about using Hotkeys to activate buttons in a GUI window. He wanted to hit the numbers 1, 2, 3, or 4, rather than clicking the individual buttons—but only for the active GUI window.

hotkeycover200While I discuss similar isolation of Hotkeys to specific active windows in my Hotkeys book, this blog provided another opportunity to show how to add more functionality to your GUIs without infringing upon other programs or Hotkeys. I attempted to make the script as simple as possible by using a number of AutoHotkey tricks. Continue reading

Use the ListView GUI Control to Find Duplicate Entries in Data Table Files (AutoHotkey Legal ListView Part 2)

ListView Control Functions in a Loop Work Quickly Locate Repetitious Data

In my last blog, “ListView GUI Control for Viewing Data Table Files (AutoHotkey Legal ListView Part 1)“, I introduced using the ListView GUI control to view and correct a data table file—in this case, an INI file (LegalInput.ini). While sorting and viewing a data table in the ListView control offers many benefits, the most power comes from the 11 built-in functions available for manipulating the control and editing data.

All GUI controls (e.g. Edit, Text, MonthCal, etc.) offer options you can call with the initial Gui, Add command. ListView (and its sister TreeView) include similar options plus special functions for directly manipulating the control. Last time, we used LV_Add() to load the data table rows into the ListView control. This time, we use the LV_GetCount() function (the number of ListView rows) to limit the total number of iterations in a loop, LV_Modify() to focus on each table row in sequential order, and LV_GetText() to retrieve and store data in the row. Continue reading

A Trick for Inserting Next Friday’s Date into Any Document (AutoHotkey Tip)

An AutoHotkey Technique for Determining Date for Any Coming Day of the Week, Plus a Pop-up for Picking Future Weekdays

“Do You Know Next Friday’s Date?”

We record upcoming events on our monthly calendars, but we live one week at a time. Most people work Monday through Friday and relax on Saturday and Sunday. If someone gives us a date for an occasion, we ask, “What day is that?”—meaning “Give me the day of the week.”

Continue reading

Swapping Dyslexic Letters (A Favorite AutoHotkey Trick)

Sometimes the Little Things Remind Me How Much I Like AutoHotkey

As I worked on one of my blogs, I accidentally transposed two letters (probably “form” for “from” or vice versa). I placed the cursor between the errant letters and hit the R key while holding down ALT. The two characters exchanged position. Pleased with myself, I decided to highlight the letter-swapping Hotkey combination in this blog as one of my favorites.

Continue reading

The Main Window for Debugging AutoHotkey Scripts

How to View the Inner Workings and Hidden Mechanisms of Running AutoHotkey Scripts

AutoHotkey includes a tool called the Main Window which aids with the debugging process. It gives you a peek into various aspects of a running .ahk script:

  1. Most recently executed lines of code (ListLines command).
  2. Current variables and values (ListVars command).
  3. Active Hotkeys (ListHotkeys command).
  4. Keyboard activity (KeyHistory command).

Main Window Menu

Open the Main Window by right-clicking on Windows System Tray icon of an active .ahk script and selecting Open from the top of the menu. The window pops open at the “Lines most recently executed” view. You can select the other three views plus “Refresh” from the View menu. Continue reading

Beginning Tips for Writing AutoHotkey Scripts

Exploring the Existential Mysteries of AutoHotkey Code and How It’s Often Misunderstood

AutoHotkeyInsightsI’ve just published my latest book, Beginning Tips for Writing AutoHotkey Script, which endeavors to clear up some of the mystery surrounding the way AutoHotkey works. You’ll find grasping how AutoHotkey processes AHK scripts a tremendous help. Quite a bit of the confusion encountered by novice AutoHotkey scriptwriters occurs through misunderstandings about the manner in which everything (life, the universe, and AutoHotkey scripts) fits together. I wrote the book with that muddiness in mind. Continue reading

The AutoHotkey “For Key [, Value] in Expression” Loop for Associative Arrays

The Standard AutoHotkey Loop Command Works Great for Incremental Series, But the For Key [, Value] in Expression Object Loop Offers Unique Flexibility for Associative Arrays

In my last blog, I introduced associative arrays to the InstantHotkeyArrays.ahk script for solving the connection problem between the Instant Hotkey combination and the insertion text. It works brilliantly—although novice AutoHotkey users might experience a slight learning curve.

On the downside of associative arrays, the standard AutoHotkey Loop command may not provide the access you need to all of the array items. Fortunately, AutoHotkey provides a command specifically for use with Objects such as true arrays: For Key [, Value] in Expression.

Continue reading