14

I just discovered AutoHotKey and it seems like a dream come true. I have two .ahk scripts, A.ahk and B.ahk. I want to call script B from within script A.

The AHK forums are strangely silent on the subject but I am sure this is possible.

3 Answers 3

16

It's the #Include directive you are looking for. You include ScriptB.ahk, then call its functions like you normally would.

#include SomeFile.ahk

http://www.autohotkey.com/docs/commands/_Include.htm

1
  • 4
    You're welcome. As a side note, I think the barrier for AHK is much higher than it needs to be because though they are thorough, the documentation and forums are a mess. It's very difficult to find help on anything but the basics. They would benefit greatly from a StackOverflow format.
    – Corey
    Dec 30, 2010 at 19:32
6

Using an #include directive is more common, but occasionally you will need to call an external AHK script. This is easily accomplished using the Run or RunWait commands. While you can pass arguments to the called script through the command line you cannot call functions within it directly. Also, this approach will create a separate thread for the called script, but that may be the point.

2

What really helped was a combination of the previous answers and a little bit of outside knowledge. I needed a script that would call more than 1 script, and since my files were in different folders, I found that I needed to specify the entire path of the files (I am sure this could be shortened but this was good enough for me at this point). I also didn't want all the different scripts that were being called to appear in the tray of the taskbar so I added an ExitApp statement at the end. So my 'generalized' code was follows. Hopefully it can help another person.

#SingleInstance, Force

; HotKeys
#Include C:\Users\username\path1\Arrows.ahk
#Include C:\Users\username\path1\HomeEndModifiers.ahk

; SoundKeys
#Include C:\Users\username\path2\VolumeAdjustment.ahk

; Opening Programs
#Include C:\Users\username\path3\OpeningPrograms.ahk

ExitApp
```
2
  • not sure this script will do that much. Include does not run the ahk file Oct 7, 2020 at 5:58
  • It does run on my machine. Please explain.
    – Diego
    Oct 7, 2020 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.