Just like driving, you need not know how to build a car from scratch. All you need to know is how to drive a car.

Same for RPA. You need not know how to build an RPA from scratch. All you need to know is how to run an RPA developed by someone else.

So in this article, let's learn how to run an AutoHotkey scripts.

1. Download and Run the Sample File

  1. Please make sure that you have installed AutoHotkey. If not, please follow the instructions in this article: Install AutoHotkey on Windows.
  2. Download the following file: autohotkey sample01.ahk
  3. Open to the folder where you have downloaded the file.
  4. AutoHotkey Explorer01

  5. In File Explorer, click View in the top menu, and make sure File name extensions is checked:
  6. AutoHotkey Explorer02

  7. You should now see the extension .ahk. Note that all AutoHotkey scripts have the extension .ahk. AHK stands for AutoHotKey file.
  8. AutoHotkey Explorer03

  9. To run the sample file, double click on this file: autohotkey sample01.ahk
  10. You won't see anything on the screen. To double check that the script is running, click the up-arrow in the task bar:
  11. Running AutoHotkey - task bar1

    You will a green icon with a "H" on it. This is the AutoHotkey icon:

    Running AutoHotkey - task bar2

    Hover over the green AutoHotkey icon. You will see the name of the autohotkey script that is currently running.

    Running AutoHotkey - task bar3

  12. Once you see this, you will know that the autohotkey sample file is running ok. Let's now go for test drive!

2. Test Drive AutoHotkey - Hot String

  1. Open the Windows Notepad
  2. Notepad

  3. type nus1
  4. nus1

    Now type a <Space>, <Tab> or <Enter>. You will see "nus1" being expanded to "National University of Singapore".
    This is what we called Text Expansion, or Hot String.

    National University of Singapore

  5. Go back to your File Explorer, right click on the file "autohotkey sample01.ahk", and elect "Edit Script".
  6. AutoHotkey Edit Script

  7. The file "autohotkey sample01.ahk" will be loaded into Notepad:
  8. AutoHotkey Edit Script in Notepad

  9. The codes that perform this Text Expansion are the 3 lines below starting in Line 16:
    • Line 16: The hotstring "nus1" is preceded by 2 colons in front, and another 2 colons at the back
    • Line 17: The keyword Send will type out the text that follows, in this case: National University of Singapore
    • Line 18: The keyword return denotes the end of the macro.

    AutoHotkey hotstring - nus1

  10. Now let's try another macro. Go back to your first notepad. This time type em1
  11. em1

    Now type a <Space>, <Tab> or <Enter>. You will see "em1" being expanded to "This email address is being protected from spambots. You need JavaScript enabled to view it."

    your_email@gmail.com

  12. The corresponding codes that perform this Text Expansion are the 3 lines below starting in Line 20:
    • Line 20: The hotstring "em1" is enclosed by 2 colons in front and at the back
    • Line 21: The keyword Send will type out the text that follows, in this case: This email address is being protected from spambots. You need JavaScript enabled to view it.
    • Line 22: The keyword return denotes the end of the macro.

    em1 macro

  13. Similarly, try btw followed by a <Space>. It will expanded to "by the way".
  14. The Text Expansion can be mult-lines too. Try type in addr1, followed by <Space>, <Tab> or <Enter>. It will be expanded to:
  15. NUS-ISS
    25 Heng Mui Keng Terrace
    Singapore 119615
    
  16. The code for this is as shown below. You simply output the 3 lines using 3 Send command.
  17. code for addr1

  18. Of course, it is also possible to use only one Send command, using the syntax {enter} to separate the lines. The curly bracket denotes the function keys on the keyboard, in this case the <Enter> key. You can try out this macro by typing addr2
  19. code for addr2

3. Test Drive AutoHotkey - Hotkey to Launch Favourite Apps

Let's now use Hotkeys to launch favourite apps.

  1. Press the keys Ctrl + Alt + N - 3 keys together - anywhere in Windows. You should see a new Notepad being launched.
  2. Notepad

    If it didn't work, make sure that you have all the 3 keys pressed together. Usually what we do is press down the Ctrl key first, don't release, then add on Alt key, don't release the 2 keys, then finally press the N key.

  3. This is what we called a hotkey. This is similar to Window's keyboard shortcut. Instead of manually clicking the Windows start menu to launch Notepad, we can now achieve the same thing using a hotkey, in this case Ctrl + Alt+ N.
  4. The codes for this hotkey can be found in Line 40:
  5. ^!n::
    Run "C:\Windows\System32\notepad.exe"
    return
    
    • Line 40: This defines the hotkey. ^ denotes the control key. ! denotes the Alt key. + denotes the shift key. # denotes the Windows key. So in this case, ^!n means Ctrl + Alt + n
    • Line 41: The keyword Run will launch the app specified as full path. In this case, the full path to notepad is: "C:\Windows\System32\notepad.exe"
    • Line 42: The keyword return denotes the end of the macro.

4. Test Drive AutoHotkey - Hotkey to Launch Favourite Folders

You can use Hotkeys to launch favourite folders in in Windows Explorer.

  1. Press the keys Ctrl + Alt + 5 anywhere in Windows. You should see the folder "C:\Windows\Temp" displayed in Windows Explorer
  2. hotkey - windows explorer

  3. The codes for this hotkey can be found in Line 45:
  4. ^!5::
    Run "C:\Windows\Temp"
    return
    
    • Line 45: This defines the hotkey: Ctrl + Alt + 5
    • Line 46: The keyword Run will launch the specified folder (in full path) in your Windows Explorer.
    • Line 47: The keyword return denotes the end of the macro.

5. Test Drive AutoHotkey - Hotkey to Launch Favourite Websites

You can use Hotkeys to launch commonly used websites in your default browser.

  1. Press the keys Ctrl + Alt + 6 anywhere in Windows. You should see the website https://www.vocabulary.com/dictionary/ opened in your default browser.
  2. The codes for this hotkey can be found in Line 50:
  3. ^!6::
    Run https://www.vocabulary.com/dictionary/
    return
    
    • Line 50: This defines the hotkey: Ctrl + Alt + 6
    • Line 51: The keyword Run will launch the specified URL in your default browser
    • Line 52: The keyword return denotes the end of the macro.

6. Test Drive AutoHotkey - Hotkey to add today's date

  1. Go back to your first notepad.
  2. Notepad

  3. Type Ctrl + Alt + d. You should see AutoHotkey type out today's date in Notepad.
  4. Notepad - td01_1

  5. You can also use the Hot String td1to type out today's date:
  6. Notepad - td01_2

  7. The codes for the above can be found in Line 54:
  8. ^!d::
    ::td1::
    EnvAdd, TodayDateTime, +0, days
    FormatTime, TodayDateTime,%TodayDateTime%, dd/MM/yyyy
    Send %TodayDateTime%{Space}
    return
    
    • Line 54: This defines the hotkey: Ctrl + Alt + d
    • Line 55: This defines the hot string: td1. With these 2 lines, you can active the same macro using hotkey or hot string.
    • Line 56: The keyword EnvAdd sets the variable TodayDateTime to the current timestamp.
    • Line 57: The keyword FormatTime formats the time to dd/MM/yyyy.
    • Line 58: The keyword Send outputs the current date.
    • Line 59: The keyword return denotes the end of the macro.

  9. You can also try the Hot String td2 that outputs today's date in the format: yyyy-MM-dd
  10. Hot String - td2

  11. The codes for the above can be found in Line 61. This is entirely similar to the Hot String td1. The only difference is that the time formatting string now becomes: yyyy-MM-dd.
  12. ^!d::
    ::td2::
    EnvAdd, TodayDateTime, +0, days
    FormatTime, TodayDateTime,%TodayDateTime%, yyyy-MM-dd
    Send %TodayDateTime%{Space}
    return
    

Add comment

Submit