AutoHotkey Quick Reference Script (Part Two)

The AutoHotkey.com built-in Index Reappears—Now to Build a Reference Tool!

autohotkeybooks160x600As I ventured in a new direction toward creating AutoHotkey reference scripts, I once again tested the previously discovered hidden AutoHotkey.com index (which had vanished). It re-emerged!

This left me in a quandary. Do I continue in my new direction or take up the original quick reference tool I began building with this AutoHotkey.com secret capability? Since the hidden index offers so much power, I decided to continue on my first course. (The possibility that the feature may disappear again looms over my work, but any Web site can change.)

I’ve written a short AutoHotkey script which uses the AutoHotkey.com index to download the pertinent HTML page source code. I tested it with both the UrlDownloadToFile command and ComObjCreate() download to a variable method described on the same page. (While both techniques appear in the script on the download page, I disabled the ComObjCreate() approach marking it as a block comment /* … */. I did not find a significant difference between the two in execution speed.)

AutoHotkey Quick Reference Script

The script below downloads whichever page AutoHotkey.com locates when appending the highlighted keyword to the URL https://autohotkey.com/docs/. I noted in the Web page source code that each command or function page included the syntax format in text surrounded by the tags <pre class=”Syntax”>[text]</pre> (e.g. <pre class=”Syntax”>Sleep, DelayInMilliseconds</pre>). That gave me the key for using the RegExReplace() function to pop-up a help window displaying the proper command or function structure.

commandsyntax
The AutoHotkey Quick Reference tool searches the AutoHotkey.com site for any highlighted text using its hidden index. If it finds a command or function, the script pops up a MsgBox, as shown above, displaying the command or function’s syntax. Click OK to load the Web page in your default browser. TickCount shows processing time in milliseconds.

 

The loaded script activates with the CTRL+ALT+m Hotkey combination:

^!m:: ; open Thesaurus.com
  StartTime := A_TickCount  ; check response time

  OldClipboard:= ClipboardAll
  Clipboard:= ""
  Send, ^c ;copies selected text to clipboard
  ClipWait 0
  If ErrorLevel
  {
    MsgBox, No Text Selected!
  Return
  }
 
  UrlDownloadToFile, https://autohotkey.com/docs/%Clipboard%, ahkref
  FileRead, RefSource, ahkref
 
   IfInString, RefSource, <pre class="Syntax"> ; IDs a command page
   {
     CmdRef := RegExReplace(RefSource,".+?<pre class=""Syntax"">(.+?)</pre.+","$1")
     CmdRef := RegExReplace(CmdRef,"<.+?>")
     StringReplace, CmdRef, CmdRef, &quot;, ", all
     ElapsedTime := A_TickCount - StartTime
     MsgBox, 1,%Clipboard%, %CmdRef%`r`rClick OK to open AutoHotkey page.`r`rTickCount %ElapsedTime%
     IfMsgBox OK
       Run https://autohotkey.com/docs/%Clipboard%
   }
   Else
   {
     Run https://autohotkey.com/docs/%Clipboard%
   }
 Clipboard:= OldClipboard
Return

 

This script uses the same standard Clipboard script format discussed in the first part of this series on the AutoHotkey.com hidden index.

In this version, the script first checks to see if the page contains command or function syntax (IfInString, RefSource, <pre class=”Syntax”>). If so, it parses that text using the RegExReplace() function and displays it with the MsgBox command. If the user clicks OK the command/function page loads in the default browser. If the hidden index does not point to a specific AutoHotkey.com page, a keyword search of the site automatically runs using the highlighted term in the Windows Clipboard.

I tested using both the IfInString command and RegExMatch() function for determining the page type but didn’t find a significant difference in speed. (The RegExMatch() function appears in the posted version as a comment.) I plan much more for this AutoHotkey reference tool, but for now, I’ve posted the current version on the Free Scripts and Apps page.

I’ll save the explanations of the RegExReplace() function for the next time. Regular Expressions are at the heart of the quick reference tool. If you want to make these powerful Regular Expressions part of your AutoHotkey scripts, then you may be interested in this introduction.

Next time, I plan to add pop-ups for each of the built-in variables and, eventually, many additional capabilities by using a GUI as the main pop-up.

jack

*          *          *

If you find Jack’s AutoHotkey Blogs useful, then please consider contributing by purchasing one or more of Jack’s AutoHotkey books. The e-books make handy AutoHotkey references.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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