Can a Mac be programmed to simulate pressing a key at a certain rate via software? Is there a way or a 3rd party application which would let me specify, for example, that I want it to send a keyboard event (so that it has the same effect as physically hitting the key on the keyboard) every 5 seconds?

So, for example, I could tell it to hit K every 5 seconds, 15 times in total?

Basically, I'm looking for something like AutoHotkey but for OS X.
I found a way to do this in a bash script:

#!/bin/sh
# Simulates hitting a key on OS X
# http://apple.stackexchange.com/a/63899/72339

echo "tell application \"System Events\" to keystroke \"$1\"" | osascript


Save as hitkey, chmod +x hitkey, hitkey k to hit K.

From there it's simple to use Automator to loop over the script several times or make an iCal alarm to initiate the script at a specific time.