当我编译时脚本自动更正错误并按下键向上键不起作用 [英] script auto correcting incorrectly when i compile and key down key up not working as well
问题描述
好吧,我的 Applescript 编辑器目前有很多问题.目前,当我执行 Key up key down 序列时,它总是会键入字母 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.
告诉应用程序系统事件"
tell application "System Events"
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
告诉应用程序Video Game copy"激活
tell application "Video Game copy" to activate
tell application "System Events"
keystroke a bunch of stuff
end tell
告诉应用程序Video Game copy 2"激活
tell application "Video Game copy 2" to activate
tell application "System Events"
keystroke a bunch of stuff
end tell
问题是当我尝试编译脚本时,应用程序名称总是更正为Video Game".
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 中的一个错误.这是一个小解决方法.我是为 jxa 编写的(用于 ui 自动化的 javascript),所以我认为你必须将它移植到 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屋!