问题
I am trying to control google earth using the arrow keys, however, I want to do this with applescript. Essentially this code should work and I'll tell you what it actually does.
tell application "System Events"
delay 3
key down 124 #Value of key right
delay 3
key up 124
end tell
This code should wait for me to go to google earth, then it will hold the right arrow key for 3 seconds. However, it just hits 'a'. I saw some recommendations to do the following:
key down (key code 124)
This sort of works, it press the right key only once and does not hold it.
If you do this with a key such as D (also used to navigate right in google earth) it works perfectly. (I think "key down 2" does that).
So my question is, is there a way to actually make the arrow keys work? "Working" here refers to sending a key down event that does not tie down the script and could later be canceled with a key up event. I would really like to be able to control the flight simulator (WASD does not work -- arrow keys do).
Thanks for all suggestions,
Jake
回答1:
This script presses the right arrow key for 3 seconds:
tell application "System Events"
set now to the seconds of the (current date)
set later to now + 3
if later > 60 then set later to later - 60
repeat while the seconds of the (current date) is not later
key down (key code 124)
end repeat
end tell
I don't know if this will work with Google Earth, but I do know that the script is correct.
来源:https://stackoverflow.com/questions/17606613/can-applescript-send-arrow-keys-via-key-down