0

The closest solution to a continuous key press that I know is just repeating a key press a certain number of times:

repeat 1000 times
    tell application "System Events" to keystroke "c" using command down
end repeat

But that's now what I'm trying to do. I need to simulate a continuos press, which means that it's like if the user keeps holding down the 'c' button for a certain amount of time. Is it possible to do that in AppleScript?

Edit I'm trying this way:

tell application "System Events"
    key down "c"
    delay 10
    key up "c"
end tell

Result: it keeps pressed "a" instead of "c". Why? I also have tried with the key code 8 (key down 8), with the same result.

  • 1
    Why do you need to press this key continuously? – William T Froggard Jan 26 '16 at 0:49
  • Key down; delay; key up should do it – Tetsujin Jan 26 '16 at 9:04
  • @Tetsujin I tried this way but it doesn't work. Give a look to my edit please. – Ramy Al Zuhouri Jan 26 '16 at 14:52
  • 1
    Seems like an X-Y problem to me. Rather than explaining what the larger picture is, OP is asking how to implement the solution they think will get them the next step closer. Or maybe you're just looking for a NO answer - AppleScript isn't designed for this type of task and gets interrupted quite often when the script is intended to hammer on the resources of the system. – bmike Jan 26 '16 at 15:54
  • I really need to continuously press a key. It's for playing a videogame in an easier way and avoid to always hold the key (and there's no way to change the key configuration). – Ramy Al Zuhouri Jan 26 '16 at 16:24

You must log in to answer this question.

Browse other questions tagged .