Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I have an AHK script which has a variable in it - how can I pass a value to that variable so that the script runs with that value?

Can I call an AHK script from PHP or Javascript - if so how? I ask this as it may be a solution to my first question (value passed when AHK script is called)

share|improve this question

Yes. From, "Passing Command Line Parameters to a Script":

AutoHotkey.exe [Switches] [Script Filename] [Script Parameters]

So from any system which can execute commands, you would call the autohotkey.exe executable with the name of your script followed by your script's parameters (which will map them to variables like %1, %2, etc).

If you were using PHP to execute this, you might use PHP's shell_exec command:

$output = shell_exec('autohotkey script.ahk arg1 arg2');
echo "<pre>$output</pre>";
share|improve this answer
Looks good - but where is the shell_exec directory? I think that my script is not being found but I am guessing. – Doclands Sep 12 '12 at 11:00
Thanks @ckhan - I can run my script from the command prompt but not from PHP which is my aim - I think that it is a directory problem - I do not know where to place my ahk script so that script_exec can find it (or which root to use so I can put the path in the scrip_exec command) – Doclands Sep 12 '12 at 11:38
Sorted - thank you - your solution is perfectly correct - I am using EasyPhP as my PhP server - the script should have been in the root directory of the server - also I needed to use %1% rather than %1. – Doclands Sep 12 '12 at 14:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .