I am a light user of AHK, but impressed by its simplicity and usefulness. About a year ago, I wanted to create a compiled utility for a USB keyboard that made it more user-friendly under Windows. The utility would implement some default behaviours, but allow the user to change and extend these as needed.
To achieve this, I wanted a single executable (no .dll) that included all the base functionality and default settings, but that could then dynamically load extra AHK scripts and bind hot keys as desired.
Much forum searching and reading ensued until I was reasonably confident what I wanted to do could not be achieved under vanilla AutoHotkey, but required the AutoHotkey_H variant. Many more hours of trial and error were spent before I had working code. This was primarily due to my own lack of knowledge, and not quite being able to grasp what was being said in the forums. This tutorial is what I wish I had discovered back then.
Install AutoHotkey_H
The aim here was to install AutoHotkey_H and be able to generate a compiled binary that included it instead of vanilla AutoHotkey.
1) Download and install AutoHotkey
https://autohotkey.com/download/
Note which version you choose - ANSI 32-bit, Unicode 32-bit or Unicode 64-bit.
2) Download AutoHotkey_H
https://hotkeyit.github.io/v2/
3) Extract AutoHotkey_H (ahkdll-v1-release-master.zip) in a temp directory.
4) Dending on which version of AutoHotkey you installed earlier, copy AutoHotkey.exe from:
ahkdll-v1-release-master\Win32a (ANSI 32-bit)
ahkdll-v1-release-master\Win32w (Unicode 32-bit)
ahkdll-v1-release-master\x64w (Unicode 64-bit)
to c:\Program Files\AutoHotkey\AutoHotkey.exe
5) Copy all the contents of
ahkdll-v1-release-master\Compiler
to C:\Program Files\AutoHotkey\Compiler
That's it! You should now be able to run AHK scripts using additional functions from AutoHotkey_H.
Use
You can now dynamically load a AHK file from your main script using:
Code: Select all
DllCall(A_AhkPath . "\addFile", "str", "path\to\your\DynamicScript.ahk", "uchar", 1, "uchar" , 0, "Cdecl UInt") ; Requires AutoHotkey_H
To compile your main script, run the following from the command line (cmd.exe):
Code: Select all
"C:\Program Files\AutoHotkey\Compiler\Ahk2Exe.ahk" /bin "C:\Program Files\AutoHotkey\AutoHotkey.exe" /in MainScript.ahk /out MainScript.exe
There you have it! A summary of what took me many hours to discover. Apologies if its stating the obvious for some - if it helps one or two fellow coders, then it's done its job