Tell me more ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Is it possible to automate the key press of a key (such as "a" or "<") in Mozilla Firefox, Google Chrome or Safari (in this order)? I'd like to automate the key press of "a" for example in Mozilla Firefox for 100 times every x seconds. With x being a value between 1 second and 10 seconds chosen randomly at every key press. What Applescript could make the trick?

Also, where can I find a list of all codes for each key of the keyboard?

share|improve this question

1 Answer

up vote 9 down vote accepted

Here's the script you wanted:

tell application "Mozilla Firefox"
    repeat 100 times
        tell application "System Events" to keystroke "1" using command down
        delay random number from 1 to 10
    end repeat
end tell

That should work to do exactly what you asked.
For key codes:

tell application "Finder"
    activate
    tell application "System Events" to key code 18 using command down
end tell

This block will automate Cmd + 1.

That will also do the same thing:

tell application "Finder"
    activate
    tell application "System Events" to keystroke "1" using command down
end tell

Here's a key code list:
Key code list #1
Key code list #2
Sources:

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.