HotString to bring up a GUI with multiple text selections in AutoHotkey

I was helping someone in an AutoHotkey Facebook group this morning.  The original request was how to have a HotString without requiring an ending character (tab, space, return, etc.).  This is solved by simply putting an asterisk in between the first two colons.

i.e.  :*:jg::[email protected]

However someone else mentioned a function they use to display a list of items and select from them.  He didn’t share his function but I found something similar on the AutoHotkey forum.   The example used the “Loop” and StringSplit commands.  I decided to adapt it to use a for Loop and StrSplit function.

HotString to bring up a GUI with multiple text selections in AutoHotkey

Here’s the code to use a HotString to bring up a GUI with multiple text selections in AutoHotkey


#SingleInstance,Force ;make sure it only runs once
:*:jg::[email protected] ;This does solve initial request

:*:gg:: ;when I type gg bring up the menu (* means don't wait for an end charachter)
TextMenu("This is, cool¦But I like¦to do more¦with these¦But that's about`n`nit")
return
:*:ff:: ;when I type gg bring up the menu (* means don't wait for an end charachter)
TextMenu("this¦is from the ¦ff choice I typed¦Pretty cool¦huh")
return

TextMenu(TextOptions){
for k, MenuItems in StrSplit(TextOptions,"¦") ;parse the data on the weird pipe charachter
Menu, MyMenu,Add,% MenuItems,Action ;Add each item to the Menu

Menu, MyMenu, Show ;Display the GUI and wait for action
Menu, MyMenu, DeleteAll ;Delete all the menu items
}

Action:
ClipboardBackup:=ClipboardAll ;backup clipboard
Clipboard:=A_ThisMenuItem ;Shove what was selected into the clipboard
Send, ^v ;paste the text
sleep, 50 ;Remember to sleep before restoring clipboard or it will fail
Clipboard:=ClipboardBackup ;Restore clipboard
return

 

AutoHotkey Webinar- Intro to AutoHotkey

In this webinar we cover an Intro to AutoHotkey.

Video Hour 1: High-level overview: Hour 1
Video Hour 2: Q&A: Hour 2

Script Highlight: Minimize to tray–  This is an “old” AutoHotkey script but is super-cool!   When running you simply press the Windows Key & H and the active program will “disappear”.  It works on multiple windows.  Then, when you want them back, press Windows & U and the windows will be visible again.

Intro to AutoHotkey

  • AutoHotkey is free, open-source, Windows scripting language
  • Created in 2003 from Chris Mallet it was an off-shoot of AutoIt
  • AHK is user-friendly for non-programmers but is also used by programmers as it “hooks” into Windows & windows programs very well
  • The core language is very descriptive and typically isn’t too hard to grasp
  • Scripts are easily “compiled” into an executable which can be easily shared
  • You do not need to install AutoHotkey to run it. (It can be run from a thumb-drive)

What can AutoHotkey do?

You can automate virtually anything on a Windows computer!  Here are some uses:

  • HotStrings: think text expansion on your phone or spell-check in MS Word
  • HotKeys: Launch programs with a click of a button
  • Files & Folders: Manipulate, read, move, delete etc.
  • Automate programs : Outlook, Word, Excel, SPSS, VLC, Adobe, etc.
  • Connect to Windows API: Programmatically affect Windows & other programs
  • Web Scrape: Reliably download data from webpages &/or manipulate /complete forms
  • Web Service APIs: Many vendors allow you to query their services
  • Create GUIs: Simplify interacting with scripts by creating a GUI to manipulate
  • Regular Expressions: use pattern matching on text files to extract or re-arrange the text
  • Audio & Image Manipulation: Screen clipping, OCR, extract audio, Video recording, etc.
  • So much more!!!

AutoHotkey Resources

Installation of AutoHotkey

Go here and download the current version of AutoHotkey https://www.autohotkey.com/download/

During installation, we recommend installing the Unicode 32-bit version of AutoHotkey

Installing a Default AutoHotkey Editor

AutoHotkey code is “plain text” and pretty easy to read

Having said that, using an editor / IDE, instead of notepad, is very helpful!

Below are links to the three most popular AHK editors.  Are all equally good as are many others).  For our demonstration we are going to use SciTE (pronounced ‘sight’)

  • SciTE4AutoHotkey  is a great editor for AutoHotkey.  Here are a bunch of videos demonstrating how to Customize SciTE
  • AutoHotkey Studio  Great editor specific to AutoHotkey.  Check out the demo in this webinar
  • Notepad ++  Another great editor which is customized for working with AutoHotkey

Before Your First AutoHotkey Script

Before we start coding, here are some basics which will help you

  1. #SingleInstance, Force: Put in all scripts. This Forces 1 instance of the script
  2. The Green icon with white H   in system tray shows you the script is running
  3. Every time you make changes to your script, you need to Reload / Launch it for the changes to take affect
  4. Frequent Modifier keys (for HotKeys) are: ^=Control #=Windows +=Shift  !=Alt
  5. Frequent Special Characters (for HotStrings) are:#,!,+,;  Wrap them with {}
    1. For a New Line, use `n, for a tab use `t

 

Your First AutoHotkey Script

Hotkey

;************Hotkeys********************
;  ^=Control #=Windows +=Shift  !=Alt
^b::Run C:\Program Files\Mozilla Firefox\firefox.exe ;Launches FireFox
^n::run notepad.exe ;Launches Notepad
~^n::run notepad.exe ;launches Notepad w/o absorbing the HotKey

HotString

;*********HotString************
::jg.::Joe Glines
:o:jta.::Hello ,How are you? {left 14}

Copy & Paste to Excel

;********************Copy selected text, activiate Excel & Paste****************
;***********Copy / Paste to other program
^b::
backup:=ClipboardAll ;create a backup of the clipboard
Clipboard:="" ;clear the clipboard
Send, ^c ;Send "Control C" to copy selected text
ClipWait,1 ;waiting for clipboard to have data
;~  MsgBox % Clipboard ;Show the clipboard has data

winactivate, ahk_exe EXCEL.EXE ;Activate Excel
WinWaitActive, ahk_exe EXCEL.EXE ;Wait for Excel to be activated
Send, ^v ;Send "Control V" to paste the data into Excel
sleep, 100 ;add 1-10th of a second to wait
Send, {down} ;send  the down-arrow key to move cursor to cell below
sleep, 100 ;wait 1-10th of a second
winactivate, ahk_exe SciTE.exe ;Activate SciTE 
Clipboard:=backup ;restore clipboard
return ;end this section

Troubleshooting & Debugging

  • Watch our AutoHotkey webinar on Troubleshooting & Debugging (or join a future webinar and ask questions in the second hour)
  • Work through our HotStrings Udemy course
  • Is script running / Green icon with white H in system tray
  • If Green H Icon, Restart script
  • Double-click icon & look at: last lines run, Variables & their contents, Hotkeys & their methods, Key history
  • Close all other scripts & programs & retry
  • If still not working, start using msgbox to “walk through” the script
  • Try using ListVars & ListLines
  • Read documentation on specific command/function you’re having issue on. Search forum/StackOverflow for examples
  • Try running your script as Admin
  • Temporarily turn-off UAC (User Account Control)
  • Is your issue after the Auto-Execute Section?
  • If Context-sensitive, remove context sensitivity & run general
  • Reboot the computer (hey, it’s Windows…)
  • Search the AutoHotkey Forum, Stack Overflow for similar issues
  • Is the problem consistent & repeatable?
  • Does it happen on other computers?
  • What, specifically, isn’t working? Break down the part that isn’t working into it’s-own script. Provide specific example to AHK Forum, StackOverflow, or friend after spending at least 30 minutes on it yourself. You can also check Discord for live feedback/support.
  • For SciTE debugging, you can check out videos on this post

 

Autocorrect replace text- Use abbreviations to automate writing!

autocorrect replace text

AutoHotkey Merchandise-White Stress ballAutocorrect replace text

Hotstrings from AutoHotKey are an amazing time saver! If you’re not using them now, stop what you’re doing because they are very easy to use and save you a lot of time on a daily basis!

You’ve probably used Microsoft Word’s autocorrect to replace misspellings or perhaps the Copyright sign ©.   Imagine if, instead of replacing one word, you could replace three pre-defined letters with paragraphs of text!   Simply one of the best ways to crank-up your productivity in a very short time!

Another video I did demonstrating the usefulness of Hotstrings can be seen here where I demonstrate how I use it with SPSS to crank-out reports.

 

Ms-office – Word – Use AutoText Or Don’tIt’s Your Choice Tutorials

AutoCorrect’s “Replace text as you type” feature is great for fixing typos, but you can save much more time by creating AutoCorrect entries for text items that you …

Windows autocorrect- Auto-replace text in any Windows program with a Hotstring from AutoHotKey

windows autocorrect Windows Autocorrect– Auto-replace an abbreviation with full text in any windows program

Years ago I realized I was frequently typing the same thing over and over. For a while I used autocorrect in Microsoft Word which was helpful but had limitations (one huge one is that it only worked in Word). AutoHotKey is a free scripting program that allows you to do an amazing amount of things; one of which is how to use Hotstrings to autocorrect text in any windows program via Hotstrings.

I have hundreds of Hotstrings which allow me to type a few letters and have them, automatically, replaced with the full word, sentence, paragraph, etc.   Below is a simple example where I want to type my main website domain.  Instead of typing the entiere thing out I just type tac. which is quickly replaced with  https://the-automator.com

 
:o:tac.::https://the-automator.com
:o:tst.::{#}Include <default_Settings>`rRAlt`::`nBrowser_Forward`::Reload`r`nRControl`::`nBrowser_Back`::`r`;{* 60}`r`n

The second example is one where I want to have line-breaks inserted (This is my template when starting a new AutoHotKey script.)  I simply type tst.  and the following “magically” appears in its place via windows autocorrect.

 
#Include <default_Settings>
RAlt::
Browser_Forward::Reload
RControl::
Browser_Back::
;************************************************************

The below video outlines how I use hotstrings to reduce the amount of mundane work that I have to do.  It is amazing how much time you can save once you get used to using them!  Remember your Hotstrings (windows autocorrect) will work in any Windows program!  Did I mention it was free?  What more could you ask for?AutoHotkey Merchandise-White Stress ball

Windows autocorrect is just one of many amazing things you can do with AutoHotKey however hotstrings is a great, easy, way to start down the path of automation and efficiency!