AutoHotkey Tip of the Week: The Eval() Function for Hotkey Math Calculations and Text Manipulation

The Classic Eval() Function Solves Problems You Didn’t Even Know You Had by Calculating and Resolving AutoHotkey Functions and Expressions Found in Text Strings!

When I work on particular AutoHotkey solutions, often I find myself in the middle of a treasure hunt—picking up hidden gems along the way. Although operative for years, I didn’t know these valuable tools existed until I went searching for answers to a seemingly unrelated problem.

EvalfunctionMsgBox2For example, the simple question about capitalizing sentences led me to the RegExHotstrings() function discussed last time. As I dug deeper into the math-side of dynamic Hotstrings, I discovered the Eval() function. While many old AutoHotkey hands have employed the Eval() function for years, I didn’t understand its power until I used it in the investigation. (Even now the Eval() function does way more than I comprehend. I’ve only scratched the surface of its capabilities.) Continue reading

Quick Tip: The Best Way to Paste with the AutoHotkey Send Command

When Using the Send Command to Paste from the Clipboard, a Simple Best Practice Can Make the Difference

tipsI’ve noticed that occasionally a couple of my Clipboard paste Hotkeys would cause a jump to the Bottom of the page in the WordPress editing window—a huge source of aggravation. Fortunately, I rarely used those Hotkeys. Then, while working on my blog for next week, I ran into the problem again in a simple capitalization Hotkey routine. This confused me since my standard uppercase, lowercase, and initial cap Hotkeys work just fine. The new Hotkey wasn’t that much different. I investigated. Continue reading

AutoHotkey Tip of the Week: A Look at the New Switch/Case Command

In the DateStampConvert.ahk Script, Rather than Using a Series of If-Else Statements (or the Ternary Operator), the New Switch Command Sets Up Case Statements for Alternative Results—Plus, Easily Add Conversions for Spanish, German, French, and Italian Date Formats

Over a year ago, I used a cascading series of the ternary operators to convert English text month names into their numeric values within a single function (“Use the Ternary Operator to Create Conditional Case Statements or Switches“). The ternary operator shortcut acts as If-Else statements in abbreviated form.

DateConvertSend
In the DateStampConvert.ahk script, a technique similar to Switch/Case statements converts the name of a month into its corresponding numeric value.

Continue reading

AutoHotkey Tip of the Week: Save Time with CodeQuickTester for Testing and Modifying Scripts

Stop Creating Temporary Files to Check Out the New Scripts You Find on the Web—CodeQuickTester Directly Runs AutoHotkey Code without Saving

Since I consider educating motivated users about how to write and implement AutoHotkey scripts my primary purpose in life, I rarely recommend specific “user-friendly” AutoHotkey tools. Although they make scripting simpler, easy-to-use programming apps often interfere with a person’s understanding of the inner workings and hidden mechanism of AutoHotkey.

Don’t misunderstand me. I’m not against anyone using any tools that make life easier but my job is to teach how to get it done—not deliver canned, finished products. That’s why I rarely review other AutoHotkey scripts. However, every once in a while, I find an AutoHotkey app (such as Ryan’s RegExTester) which enhances understanding while making the coding process a little easier. CodeQuickTester by GeekDude falls into this category. 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: Add Power to Any Command with Forced Expressions (%)—October 7, 2019

Use the Forced Expression Operator (%) to Adapt AutoHotkey Commands On-the-Fly

Light Bulb!Most AutoHotkey Version 1.1 commands use plain text as parameters. That means AutoHotkey interprets the text exactly as written—no quotes needed and no variables accepted. In version 1.1, this would limit the commands except for the availability of the traditional (or legacy) double-quote text replacement operator (%var%).

The %var% technique allows us to substitute any variable directly into an AutoHotkey command. However, using the forced expression operator (%) adds even greater flexibility and power to almost any AutoHotkey code. In many cases, rather than developing complicated subroutines, you can use this technique to embed expressions and functions directly into version 1.1 AutoHotkey commands. Continue reading

AutoHotkey Tip of the Week: Instant Upper Case, Lower Case, and Initial Cap Text—September 2, 2019

Tips: Quick Hotkeys for Changing Text To/From Capital Letters and How to Initial Cap Everything, Plus, How to Write Robust Clipboard Routines

Light Bulb!This week I offer two useful tips: one for editing text and the other for improving your AutoHotkey scripts.

When reviewing my books, I look for those tips which I use all the time. I’ve found that I developed some scripts primarily for demonstration purposes and rarely ever use them again. Yet, I have a few which I use so much that I feel like they have become a part of my Windows system.

AHKNewCover200In this case, while perusing my Beginner’s Guide to AutoHotkey, I noticed in “Chapter Four: Hotkeys and Text Editing with Windows Clipboard” the Hotkeys for changing selected portions of text into all capital letters, all lowercase letters, or initial cap every word in the section. I originally wrote these Hotkeys when I edited articles submitted by freelance writers.

Some writers have a penchant for placing their article headlines and topic subheadings in all uppercase letters. By creating a Hotkey for converting the entire line to Title Mode (initial capital letter for each word), I quickly solved the retyping problem:
Continue reading

AutoHotkey Tip of the Week: How to Combine Multiple Scripts into One—August 19, 2019

Design Your Scripts to Either Run as Stand-alone Apps or Use the #Include Directive to Integrate into a Master Script without Modification

Light Bulb!Cover 200 Border

The cool thing about this tip is that, after you implement these techniques—without any additional changes—you can run your AutoHotkey script as an independent app or quickly add it to a master script. 

In “Chapter Eleven: How to Write Easy-Merge AutoHotkey Scripts” from the book Beginning Tips for Writing AutoHotkey Scripts, I outline steps for writing scripts which easily combine with other scripts without conflict. This allows the AutoHotkey user to run multiple apps without needing to launch each script individually. (It also prevents the accumulation of numerous AutoHotkey icons in the Windows System Notification Tray.) If you employ these basic design tips when writing your apps you’ll find that you don’t need to do any rewrites when combining useful scripts. Continue reading