How to make applescript hold a key for 2 seconds So I am trying to make a script that moves me forward and backward to prevent afk in a game but the game is not registering the key as it is too short here is what I have so far.

repeat 100 times
        tell application "System Events" to keystroke "w" using command down
    delay (random number from 0.5 to 3)
        tell application "System Events" to keystroke "s" using command down
    delay (random number from 3 to 4)
end repeat
You probably want key down &amp; up as separate events...

repeat 100 times
    tell application "System Events"
        key down {command}
        key down "w"
        delay (random number from 0.5 to 3)
        key up "w"

        key down "s"
        delay (random number from 3 to 4)
        key up "s"
        key up {command}
    end tell
end repeat


[untested as I've nothing to really test it on]
Now tested as working on a similar game structure.