首页 文章

Applescript可以通过按键发送箭头键吗?

提问于
浏览
0

我试图使用箭头键控制谷歌地球,但是,我想用applescript做这个 . 基本上这个代码应该工作,我会告诉你它实际上做了什么 .

tell application "System Events"
     delay 3
     key down 124 #Value of key right
     delay 3
     key up 124
end tell

这段代码应该等我去google earth,然后它会按住右箭头键3秒钟 . 然而,它只是命中'a' . 我看到了一些建议,要做以下事情:

key down (key code 124)

这种工作,它只按一次右键而不保持它 .

如果你使用诸如D之类的键(也用于在Google地球中导航),它可以完美地运行 . (我认为“关键2”确实如此) .

所以我的问题是,有没有办法让箭头键正常工作?这里的“工作”是指发送一个不关闭脚本的按键事件,以后可以通过按键事件取消 . 我真的希望能够控制飞行模拟器(WASD不起作用 - 箭头键做) .

谢谢你的所有建议,

可靠的人

1 回答

  • 1

    此脚本按下右箭头键3秒钟:

    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
    

    我不知道这是否适用于Google地球,但我知道脚本是正确的 .

相关问题