Mac OSX Apple Script, How do I make Apple Script push keys on an application What I am trying to do is make my character run up 50 steps then down 50 steps repeatedly using the up key and the down key. I know how to utilize system events to push keys and I know how to tell applications to do certain things but what I put together so far is not looking right. I am pretty much new to this, and I am trying to learn a bit, please help!!
You might also add a delay somewhere in the loop to make it easier to stop the script:

activate application "TextEdit"
delay 0.5 -- time to release modifier keys if the script is run with a keyboard shortcut
tell application "System Events"
    repeat while name of (process 1 where frontmost is true) is "TextEdit"
        repeat 50 times
            key code 126 -- up
            delay 0.1
        end repeat
        repeat 50 times
            key code 125 -- down
            delay 0.1
        end repeat
        delay 0.5
    end repeat
end tell


See Events.h or my website for the key codes.