Preparing for AutoHotkey Version 2.0 (Even If You Don’t Need It)

Many AutoHotkey V1.1 Commands Offer Parallel Functions Which Run in Both V1.1 and V2.0—It Makes Sense to Use Them Now

I recently noticed an evolution in the online AutoHotkey documentation. Over the past number of years, the powers-that-be have added new functions which serve the same purpose as the traditional command. Yet, they have made no particular effort to highlight the significance of those functions. That has changed.


Previously, this function syntax would appear in the online command description directly below the command syntax—as if merely an option. Now when you look up a command which has a parallel function (e.g. the StringReplace command), you get a warning similar to the following:

Deprecated: This command is not recommended for use in new scripts. Use the StrReplace function instead.

The “Deprecated” warning includes a link which jumps to the recommended function—sometimes in the same page and sometimes in a new page as follows:

Deprecated: IfEqual, IfNotEqual, IfLess, IfLessOrEqual, IfGreater and IfGreaterOrEqual are not recommended for use in new scripts. See Scripting Language: If Statement for details.

As long as you use AutoHotkey V1.1, you’ll find no requirement to use the newer function. However, for a couple of reasons, I recommend you do so.

The AutoHotkey V1.1 Command Goes Away in AutoHotkey V2.0

As I’ve emphasized in the past, no one will force you to abandon AutoHotkey V1.1 and move onto V2.0. That means you can continue using the current version as long as you like—maybe forever. Yet, just in case you decide to dip your toe into V2.0, using the recommended functions makes it easier.

These currently available parallel functions work in both versions of AutoHotkey in the same manner as the commands. Only the syntax and location of the parameters differentiate their look and feel.

The first command variable Clipboard moves to the front of the line for assignment of the new value. All other parameters sit inside the function’s parentheses with plain text enclosed with double-quotes. The StrReplace() function defaults to All while the command requires the parameter.

Note: The syntax change for the StrReplace() function looks similar to the future V2.0 FormatTime() function discussed in an earlier blog, except that the StrReplace() function already exists in V1.1 whereas FormatTime() does not.

The first Clipboard variable in the command (the output) turns into the function’s assignment variable. The second Clipboard (the input) becomes the first parameter in the function.  The other two parameters (the Search Text and Replace Text, respectively) sit inside the function’s parentheses enclosed with double-quotes. The StrReplace() function defaults to replacing every occurrence of the search term while the command requires specifying the All parameter.

If you use the new function rather than the older command, you won’t need to change it if you decide to eventually convert to V2.0. That will save a tiny amount of work. But, even more important, if you use current alternative V1.1 functions, you’ll begin understanding how much of V2.0 operates.

Learn More About How AutoHotkey V2.0 Works While Using V1.1

Since some AutoHotkey V1.1 commands include parallel V1.1 functions compatible with both the current and future versions of AutoHotkey, why not use that function—if available? You get the benefit of learning how V2.0 functions operate without ever leaving V1.1. You’ll find these V1.1 functions reflect how many of the future V2.0 functions look and perform.

Expressions for Everything in Functions

The AutoHotkey V1.1 StringReplace command uses plain text for both the Search and Replace strings (no quotes required). In fact, if you want to use a variable with the command, you must enclose it with percent signs (%var%). This limits the command since you can only use an evaluated expression in the command if you force it by preceding the expression with a single percent sign (% expr).

The function offers more flexibility since each parameter can directly accept an expression—whether a single variable or a longer set of evaluated variables and operators. However, as a rule, if using plain text in a function parameter, you must enclose the string with either single or double quotation marks. (Tip: In V2.0 if you need to use any double-quotes in plain text, enclose the entire string with single quotes.)

After using a few of these current parallel functions in your new scripts, they will begin to feel comfortable. By opting for these functions when writing your V1.1 scripts, you learn important conventions in AutoHotkey V2.0. That will make life easier if you ever decide to make the switch.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s