脚本自动纠正错误,当我编译和键向下键涨不工作,以及 [英] script auto correcting incorrectly when i compile and key down key up not working as well
问题描述
好吧,我现在有很多的问题,与我的AppleScript编辑器。目前当过我做了主要上行键,顺序它将始终键的字母A.例如
alright I'm currently having a lot of issues with my applescript editor. currently when ever i do a Key up key down sequence it will always key the letter A. for example.
告诉应用程序系统事件
key down "u"
key up "u"
delay 1
end tell
这将击键A和我不知道为什么。
this will keystroke A and i don't know why.
^那只是一个小问题,但我的大问题是,我想三个不同的视频游戏的应用程序之间切换。他们是同一个游戏中的所有副本。我的继承人基本的脚本怎么回事。
^ thats only a minor issue though my big problem is that i want to swap between three different video game applications. They are all a duplicate of the same game. Heres how my basic script goes.
告诉应用程序视频游戏激活
tell application "Video Game" to activate
tell application "System Events"
keystroke a bunch of stuff
end tell
告诉应用程序视频游戏副本来激活
tell application "Video Game copy" to activate
tell application "System Events"
keystroke a bunch of stuff
end tell
告诉应用程序视频游戏拷贝2启动
tell application "Video Game copy 2" to activate
tell application "System Events"
keystroke a bunch of stuff
end tell
问题是,当我尝试编译脚本的应用程序名称始终更正为电子游戏。
The problem is when i try to compile the script the application name always corrects to "Video Game".
如何防止它正确编译在任何想法?
Any ideas on how to keep it from compiling in correctly?
我试图把在一个虚假的名字,那么当AppleScript的问我找到我的应用程序单击浏览搜索框下正确的。它仍然会编译错误。
I have tried putting in a bogus name then when applescript asks me to find the app i click the correct one under the browse search box. and it will still compile incorrectly.
多谢:)
推荐答案
你的描述似乎AppleScript的一个bug。下面是一个小的解决方法。我写它JXA(JavaScript进行UI自动化),所以你必须将它移植到AppleScript的,我认为:
what you describe seems a bug in applescript. Here is a little workaround for that. I wrote it for jxa (javascript for ui automation), so you have to port it to applescript i think:
ObjC.import("Cocoa");
function key(aiKeyCode, aiDelay)
{
var source = $.CGEventSourceCreate($.kCGEventSourceStateCombinedSessionState),
keyDown = $.CGEventCreateKeyboardEvent(source, aiKeyCode, true),
keyUp = $.CGEventCreateKeyboardEvent(source, aiKeyCode, false);
$.CGEventPost($.kCGAnnotatedSessionEventTap, keyDown);
delay(aiDelay);
$.CGEventPost($.kCGAnnotatedSessionEventTap, keyUp);
}
这篇关于脚本自动纠正错误,当我编译和键向下键涨不工作,以及的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!