Thursday, 23 May 2013

AutoIt or AutoHotkey?

It can be very useful indeed to be able to run simple scripts to set up macro hotkeys to fire off a whole load of commands, even controlling other running apps. Even better if you can use it for more interactive tasks, as a general purpose programming tool, allowing neat and functional GUIs with ease.

For example, for my radio use I developed an AHK script that can be drag-n-dropped onto a standalone interpreter .exe (portable - no install required) that fires up several small copies of WinAmp audio player, each configured to a different soundcard and routed to its own channel on the mixing desk. It gives me the ability to select a random track at the press of a button, from the library of hundreds of tracks - ensuring variety by removing any tendency to stick to my same old favourites.

My script can stop/start a WinAmp instance by referencing its name (WinAm1/WinAm2/WinAm3 etc), mute the audio or bring it up to normal again, seek to 30s into the track (lots of tracks take time to get going, so it's quicker to audition them some way in, when they're well under way), pause, restart, etc. Another window shows me a list of jingles, and double-clicking one will automatically load it into the usual 'cart' ready to play, and tick a box so that I can see that I've already used it in the show. The small main GUI window has an Exit button that closes everything it opened, tidying away everything in one fell swoop.

The script is over 400 lines long, and it helps that Notepad++ colours the syntax for me (Language.. A.. Autoit) but I'm glad I commented as I went (back in 2011) because a couple of years down the line there are parts that are now bafflingly odd without my comments to explain it!

So... AutoIt or AutoHotkey?

In the beginning there was AutoIt and it was good. But lacking. Lacking enough for Chris Mallett to break away and develop AutoHotkey as an alternative, because his proposal to integrate hotkey support into AutoIt v2 failed to generate response from the AutoIt community.

Chris Mallett : "The AutoHotkey project began about two years ago because I loved AutoIt v2 but wanted faster, better, and built-in hotkeys. Although AutoHotkey does not use any AutoIt v2 source (I didn't even know its source had been released), it does use AutoIt v3 source for about 34 commands, such as Process and FileCopy. In addition, AutoHotkey includes ahk2exe, which is a modified version of Jon's script compiler. In addition, it includes AutoScriptWriter (the macro recorder) and Window Spy, both of which were written by Larry Keys. So thanks to Jon, Larry, and the other AutoIt developers for all their innovation, hard work, and generosity."

So that explains why AHK exists. Me, I had already gotten used to AHK's odd syntax and was well underway to achieving what I needed before I heard about AutoIt, so I wasn't sufficiently impressed to switch even if I had reason to. I found the AHK forums and documentation were friendly and helpful, so there wasn't any point in changing just for slightly clearer more BASIC-like syntax in places. I can adapt to anything, verbose BEGIN/END, C/Java/etc's {} or Python's Significant Whitespace - it makes no real difference to me. Sometimes AHK drives me nuts and it seems like Every. Single. Line. Of. Code. needs to be researched as I go, but it's worth the pain in the end. There is no simpler way to intercept hot keys and control other programs already running. How much code would it take in a conventional programming language to do the following?

 ; simple example
F12::
msgbox You pressed F12
return

That's an AHK script in its entirety - and one of these four lines is a comment! Even though - as a software dev - I find it painful that the message isn't in quotes (to be fair, you can do that if you want - msgbox % "You pressed F12" - but that doesn't make the scripts all over the www more readable), it's still packing a remarkable amount of functionality into those few lines, tapping into the very heart of Windows to intercept the key handling routines.

A quick bit of more history, to help you to decide between the two competing camps :
As AHK progressed, tension arose between AHK and AutoIt - "AutoIT is no longer open source. Before AutoHotKey existed, AutoIT v3 was open source. According to the AHK help file, AutoHotKey adapted source code from AutoIT v3 such as Window Spy and the script compiler. When Autohotkey launched, disagreement happened between the creators of AutoIt and Autohotkey because Autohotkey placed advertisements on Google that directly targeted AutoIt v3 searches and displayed Autohotkey as a "sponsored link" ad for Autohotkey app. This included posts on the AutoIt forum that the Autohotkey creator posted with link to his software. Shortly afterwards, a new version of AutoIt was released as closed source." - http://www.wikivs.com/wiki/Autohotkey_vs_AutoIt_v3

.. so the upshot is : no matter what the capabilities of either program, if you prefer to select your software based upon how Open it is, then only AutoHotkey fits the bill; AutoIt may be Freeware but it is Closed Source. With Closed Source I always wonder why - what are they hiding and for what good reason? With Open Source it feels like the project will live for as long as I could possibly want and I won't be wasting my time learning it.

Want to decide based upon more technical merits? http://stackoverflow.com/questions/1686975/choosing-a-windows-automation-script-language-autoit-vs-autohotkey is a good start. Or Google for : autoit vs autohotkey

1 comment:

  1. Thank you for pointing out the most important reason to stick with autohotkey.

    ReplyDelete