A brief post about a fantastically useful little utility – AutoHotKey. This is a small, free, very flexible and powerful program for Windows which has potentially unlimited usefulness. It allows the user to either a) define a string of mouse/keyboard inputs (i.e. macros) which can be triggered with a single key-press, or b) re-map a particular keyboard/mouse/whatever input to act as if it’s any other kind of input. All this can be achieved either with a fairly simple scripting language, or by the use of AutoScriptWriter – a means of ‘recording’ a sequence of inputs that can then be ‘played back’ at much faster rates.
I use it for some of my fMRI stimulus programs. The MRI scanner sends out a TTL-like pulse at the beginning of every functional volume acquisition (or ‘TR’) and this can be used to synchronise with external equipment – in fMRI it’s important to know exactly when your stimuli were presented (relative to the volume acquisition sequence) in order to generate an accurate statistical model. The pulse from the scanner goes into a little USB adapter doo-hickey, which is plugged into the computer running the stimulus program – the USB box simulates a joystick button-press every time it receives a scanner pulse. This works great, except that when I’m writing my programs in my office, I don’t have a joystick, and also sometimes I want to start my programs manually (for demo purposes, or whatever). The solution? I write all my programs to start with a left-mouse click, and run an AutoHotKey script on the stimulus-program computer in the scanner room which transforms the game-port input to a left-mouse-click. This is the script in its entirety:
Simple, huh? In this way, my programs can start either with a left-mouse-clickorwhen they receive the input from the scanner on the game-port, and I don’t have to change them at all when I move them from my office machine to the scanner-room computer. It works perfectly. There’s loads of good help, advice and sample scripts on the AHK website/forums – a quick search will usually bring up something at least somewhat-related to what you want to achieve.
It’s also possible to play a very mean prank on somebody by running a script on their computer re-mapping several (or even all) of their keyboard keys to other random keys, but the less said about that the better…
Mac users are out of luck with AutoHotKey I’m afraid – it’s Windows only. However the built-in Automator application in Mac OS X has a lot of the same macro-like functionality, and is pretty easy to use once you get the hang of it. For the input re-mapping side of things IronAHK looks like a good (and very powerful) free option, and KeyRemap4MacBook also looks good – less powerful, but a much more user-friendly interface.
Happy key-hacking! If you find a good use for AHK, then let me know in the comments. TTFN.
A common issue in psychology research is getting various bits of hardware linked up in the right way. To take a simple example, I mentioned in this post that you can build a simple response box for your experiments, but (deliberately) neglected to mention what happens with the signals from the response box at the computer’s end. How does the computer ‘know’ that your participant has pressed one of the keys? The answer is TTL (Transistor-Transistor-Logic) signals. TTL signalling was invented back in 1961, and intended as a standard way for a piece of electronic equipment to send bipolar logical signals (i.e. 1=on and 0=off) to another piece of equipment. Long before ethernet, the internet or TCP/IP, this was how computers communicated with each other. TTL-type signals can be presented through most computer’s parallel and serial ports. Read the rest of this entry