AutoHotkey V1.1 Mega System Walkthrough

I built a system using AutoHotKey V1.1 for a team that grew to 6 one day at a time over the course of 5 years. AutoHotKey combined with Python and and a complete unwillingness to waste time on menial tasks saved thousands of hours of wasted time, allowed for catching of an untold number of errors, improved the accuracy of my team, and I’m positive saved the company $100k+ in PCBs that would have been built incorrectly. Of course, I’m biased. Who knows!

I’m not going to share my exact code, but I’m going to approach this as a tutorial for building a mega system. I’m sure this system isn’t perfect so use it how you will. It’s a bit more complex, but once you realize we have a file for default shortcuts that never changes, a file for the user’s configuration with overwrites, and a file for our code, it’s not all that bad.

Example 1: Using AutoHotKey to Type Text in a Multi-User System.

  • Create Default_Keys.ahk
  • Paste the code below. This defines a shortcut as a variable. The semicolon is a comment. It shows what the default shortcut is, the text that will be typed (which is defined later),a user defined variable, and today’s date.
ThisFunctionTypesText_Key:="^k" ; control + k ; Any Text You Hate Typing - ABC - 10/30/2025

  • Create User_Personal_Settings.ahk
  • This file lets your users overwrite your shortcuts. We will define the variable MY_INITIALS = ABC which we’ll use later. We will also overwrite the definition of ThisFunctionTypesText_Key. So maybe Jim on our team doesn’t like Control + k for this and would prefer Control + 6. Fine.
; ----------------------------- SET THIS TO BE YOUR INITIALS -----------
MY_INITIALS = ABC

ThisFunctionTypesText_Key:="^6" ; control + 6

  • Create Macro_Code.ahk. This will be your main code file.
; -------------------------  INCLUDES ---------------------------
#include Default_Keys.ahk ; Do not edit this file. Ovewrites are handled next.
#include User_Personal_Settings.ahk   ;  Overwrites to macro keys should go here.


; ----------------------- FUNCTION SHORTCUTS -------------
; %Keystroke name calls  function
; %ThisFunctionTypesText_Key  calls   ThisFunctionTypesText
Hotkey, %ThisFunctionTypesText_Key%, ThisFunctionTypesText


; -------------------------  FUNCTIONS  ---------------------------
ThisFunctionTypesText:
	SendInput, Any Text You Hate Typing - %MY_INITIALS% - %A_MM%/%A_DD%/%A_YYYY%
Return

Macro_Code.ahk should be in your Windows startup file. If you change it, re-start it in the Windows tray thing by the clock by right clicking on it.

The above code will type: Any Text You Hate Typing – ABC – [today’s date]

We learned:

  • We can include files
  • We can set a desired shortcut as a variable
  • We can re-define that shortcut variable in another file and that’s super handy for multi-user situations
  • We can create constants such as a user’s initials. This is useful for pathways, API keys, etc that are specific to the user.
  • AutoHotKey can type a message for us using the variables as well as system variables such as date.

Example 2: Using AutoHotKey and Python For POWER

Now we get serial. Super serial. (It’s similar to “serious”.)

  • We are going to our website of interest. Let’s say it’s https://SomeWebsite.com/id/3a9ds9s/
  • We want open https://SomeWebsite.com/id/3a9ds9s/quote, https://SomeWebsite.com/id/3a9ds9s/approval, https://SomeWebsite.com/id/3a9ds9s/order
  • We need the 3a9ds9s to pass to Python so Python can generate these URLs and open them in our browser of choice.
  • We’ll navigate to https://SomeWebsite.com/id/3a9ds9s/, highlight the URL, and hit Control + C to store it in the Windows clipboard.
  • We’ll push our shortcut key (F3) and then 3 tabs will magically open in Chrome/Edge/whatever you choose.

Let’s add the Open_Three_Tabs function below to the bottom of Macro_Code.ahk.

Tasks

  • Create a projects folder for your Hotkeys and create a “Open_Three_Tabs” folder in side.
  • Download OpenThreeTabs.py and place in your Hotkeys folder. You can grab it here: https://github.com/brandondrury/Open3Tabs
  • Add these 2 lines to your User_Personal_Settings.ahk Note: You can place this anywhere before the function we are about to call, but this method allows your other users to adjust the path for their computer. (More complicated and simpler at the same time…if you have a multi-user system).
; Add this to User_Personal_Settings.ahk 
;Change to your correct path on your computer
PROJECTS_FOLDER = C:/Users/[PATH TO HOTKEYS]/Scripts
; Add this to Default_Keys.ahk
; The shortcut for this action will be F3
Open_Three_Tabs_Key = F3
; Add this to the function shortcuts section of Macro_Code.ahk
; When the Open_Three_Tabs_Key key is pressed, the function Open_Three_Tabs will be called
Hotkey, %Open_Three_Tabs_Key%, Open_Three_Tabs
; Add this to the bottom of Macro_Code.ahk



Open_Three_Tabs:

        ; Our clipboard value must start with this or we'll pass an error.
	DesiredText = https://SomeWebsite.com/id/


        ;  If our clipboard value contains our desired text, we'll proceed.
	if (  InStr( clipboard , DesiredText)  > 0 ){

                ; open terminal, but don't don't type until it's done loading.
		run cmd.exe
		WinWaitActive , ahk_exe WindowsTerminal.exe ;


                ; This will be typed by AHK in the command line to run our commands
		Sendinput {Text} cd %PROJECTS_FOLDER%\Open_Three_Tabs\
		Sendinput {enter} ; go to script's folder

                ;  Our clipboard will be sent as the URL argument to the Python script
		Sendinput {Text} python OpenThreeTabs.py --URL %clipboard%  
		Sendinput {enter}	

		Sendinput {enter}



	} else {
                ; error message
		MsgBox , A SomeWebsite.com URL must be in the clipboard.

	}

Return

We Learned:

  • We can save pathways for our specific system in our default keys file without touching the remaining files.
  • We can use the clipboard value as a value in Python.
  • After pressing Control + C, we can now press a key like “F3” and run a Python script based on the values in the clipboard.
  • Python has many strengths. It can interact with Windows. In this case, it can open URLs in a web browser.

Example #3: Process a File In Windows and Python Using AutoHotKeys

Let’s say we have a header line that causes problems in a human-readable file ( .txt, .csv, etc). Let’s push “F5” and let AutoHotKey talk to Python via cmd.exe. Python can edit that file and save it for us.

Install Explorer Library

Setup Script

; Place in Macro_Default_Keys.ahk
; The key to trigger Drill Header Fixer will be the "F5" key
Drill_Header_Fix_Key = F5
; Link the shortcut to the function in Macro_Code.ahk
Hotkey, %Drill_Header_Fix_Key%, Drill_Header_Fix
; Add the function to Macro_Code.ahk

Drill_Header_Fix:
	directory  := Explorer_GetPath()  ;  Grab Windows Directory of selected file.

	run cmd.exe
	WinWaitActive , ahk_exe WindowsTerminal.exe ;

	Sendinput  {Text} cd  %PROJECTS_FOLDER%\Drill_Clean\
	Sendinput {enter} ; go to script's folder

	Sendinput {Text}  python Drill_Clean_Directory.py  --Brandopath "%directory%"  
	Sendinput {enter}

Return

We’ll find a drill file. If you need one, there’s one in the DrilL_Clean repository in OrigFiles. https://github.com/brandondrury/Drill_Clean/tree/main/OrigFiles

Select that drill file. Press F5. Autohotkey will call the Drill_Header_Fix function. The Explorer library will grab the location directory of that drill file. The function will open the command line terminal, change the directory to our Drill_Clean folder and call the drill clean Python file with the argument “–Brandonpath” with the Windows directory.

The Python script does the work of commenting out all the junk files from there.

Of course, I doubt if many people need to fix drill file headers, but this opens the possibilities of doing any Python activity you’d like on files on your Windows computer.

We Learned:

  • AutoHotKey has libraries/extensions that add tremendous power.
  • We can select a file in Windows and push one button to process it with Python.

AutoHotKey GUI?

Yup. If we don’t want to remember a ton of shortcuts, we can make a GUI. The GUI options aren’t hyper comprehensive, but they get the job done. Let me know if you’d like to see how I did this.

Other AutoHotKey / Python Ideas

  • https://github.com/brandondrury/UnzipAndDelete Select a zip file in Windows. Press your shortcut. The file is unzipped and the original zip is deleted. You can comment out the deleted line part if wanted to hang on to the original zip. Follow Example #3 as it’s nearly identical to this one.