【问题标题】:Why does this script work only if I use delay?为什么这个脚本只有在我使用延迟时才有效?
【发布时间】:2012-10-28 14:02:29
【问题描述】:

我正在编写一个小脚本来自动化注册扑克锦标赛的过程,同时玩其他几张牌桌。 大堂窗口在后台,在前台有其他桌子在玩的时候弹出。所以为了注册,我需要在前台设置大厅(ctrl + 1)并防止应用程序弹出其他表(我使用了重复循环来执行此操作,但我不确定这是否是最好的方法)。

我不明白为什么,当我将这些延迟设置为 0.5 或 0.2 时,脚本会按预期工作,否则如果我在没有它们的情况下运行脚本,它就不起作用(不要点击大厅的注册按钮)。

这很关键,因为在这 0.5 秒内可能会有其他桌子弹出并从主大厅抢走焦点。请注意,我使用像素坐标来单击按钮,因为它是一个非 Cocoa 应用程序并且不允许我轻松单击按钮。

我该如何解决这个问题?

--REGISTRATION PROCESS
--make sure we complete the reg process without other tables popping up and stealing focus from the tourney reg window
set done to false
repeat until done is true
    delay 0.5
    --Lobby focused
    tell application "System Events"
        set frontmost of process "PokerStarsIT" to true
        keystroke "1" using command down
        delay 0.2
    end tell

    --Start the registration process: click "register" button.
    tell application "PokerStarsIT"
        do shell script quoted form of POSIX path of mouseToolsPath & " -x " & (xCoordinate as text) & " -y " & (yCoordinate as text) & " -rightClick"
        set done to true                
    end tell
end repeat

【问题讨论】:

    标签: macos applescript delay


    【解决方案1】:

    我会这样尝试。请注意,我将窗口 1 的名称用作“大厅”。确保输入窗口的实际名称,即那里的大厅窗口。您还会注意到“do shell script”命令不在 PokerStarsIT 应用程序 tell 代码块内。 “do shell script”是一个applescript 命令,而不是PokerStarsIT 命令。另外我认为你应该做“-leftClick”而不是“-rightClick”。祝你好运。

    tell application "PokerStarsIT" to activate
    tell application "System Events"
        tell process "PokerStarsIT"
            repeat
                keystroke "1" using command down
                if name of window 1 is "Lobby" then exit repeat
            end repeat
        end tell
    end tell
    
    --Start the registration process: click "register" button.
    do shell script quoted form of POSIX path of mouseToolsPath & " -x " & (xCoordinate as text) & " -y " & (yCoordinate as text) & " -leftClick"
    

    【讨论】:

    • 感谢您的努力!我不知道为什么它部分工作,它只在第一次正确点击,然后在注册第二次锦标赛时它没有点击。哦,如果我按照你写的那样运行它,它就找不到 POSIX 路径。但是,脚本中可能存在其他影响其正确行为的错误。我已将脚本粘贴在这里:pastebin.com/uw6vHcYA。如果你愿意,你可以看看并告诉我为什么这不能按预期工作。请注意,在完美世界中,脚本中不应存在“延迟”。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-06
    • 1970-01-01
    • 2018-01-18
    • 2020-03-06
    • 2015-09-14
    • 2020-07-24
    • 2015-05-26
    相关资源
    最近更新 更多