🅰️HK Lesson #4: Writing your 1st 🅰utoHotkey Script!

Hello,

Today we’re going to cover some tips to get you started on your first AutoHotkey script! 

One of the first lines of code you probably should get familiar with right away is #SingleInstance

I don’t have a clue while this isn’t the default behavior as 99.99% of scripts I write I only want one instance of it.  Adding #SingleInstance to your script will “force” AutoHotkey to only allow a single instance of your script running at one time.  To me this is something you’d want in virtually all of your scripts otherwise you always have a message box pop up and ask you if you want to have multiple instances of the script running.

#SingleInstance

We need to have something in the script or it will exit faster than a politician will breaking his promise to you, so let’s start off with the goal so many languages show first: How to create a message box with “Hello World” displayed.

 AutoHotkey is amazingly simple and here’s a great example of it:

MsgBox “Hello World” ;simple example showing a messagebox

Yes, it really is that simple.   The command MsgBox is doing a lot of the “heavy lifting” behind the scenes. 

Now of course it’s better to actually see the msgbox instead of taking my word for it which means you need to launch/run the script.  Here are a couple main ways you can do this.

  • Double-click the file from Explorer
  • Use the IDE / Editor to launch it.

Your first AHK Script  Extract from Intro to AHK v2
Your first AHK Script  Extract from Intro to AHK v2

Don’t forget the course is over 4 hours long and you can or get a 15% discount to the Intro to AHK course by clicking here.

If you downloaded SciTE4AutoHotkey, F5 is the hotkey that will launch the active script or you can mouse-over the toolbar looking for a blue triangle to click. 

Now that you have the script running you should see a green box with a white H in the system tray Green H in system tray

The location of your system tray may vary depending on your settings however for 99% of people it is the bottom right of your main screen (often where the clock is)

When first starting out, being sure your script is actually running is one of the simplest ways to “trouble-shoot”.  Often people have an error in their script which prevents the script from actually running.  If there is no icon, your script is not running and there is ZERO chance that it can work! (duh!)🤣

So, now that you’ve launched the script, you should see your “Hello World” message box

Keep in mind, when we make a change to our script – we need to save and restart script to see the changes in the running program.

Additional Resources

Joe, Isaias, Irfan & Team

the-Automator.com

This campaign was designed to allow you to jump around.  At any time you can jump to any one of the emails by clicking below

1) Intro2) AHK Versions3) Editors4) First AHK Script5) Getting Help
6) Variables7) Run @ Startup8) Downloading Viruses9) HotStrings10) Hotkeys
11) One vs Many Scripts12) Intro to QAP13) Functions & Directives14) Custom Functions15) Includes & Lib
16) Troubleshooting17) Intro to GUIs18) Using Clipboard19) Reading Files20) Saving Preferences
21) Automating older Progs22) Automating Menus

P.S.  A lot of people don’t join the AHK Hero group because they think that they are not experienced enough, but the majority of the Hero Members are new to AHK as well and we have dedicated AHK Hero meetings to help them out. Remember that if you are member, you get a 25% discount to all our courses❗

Comments are closed.