循环剪贴板和错误级别评估无法按预期工作

时间:2013-08-11 20:12:50

标签: autohotkey

while clipboard =
    {
        SendEvent, ^{ins}                                   ;^c doesn't work
        sleep 50
    }
    clipWait, 2                                     ; Wait for the clipboard to contain text.
    if ErrorLevel
    {
        ;endEvent, ^{ins}
        MsgBox Failed to save the selection: %clipboard%
        ;exit
    }

问题:ErrorLevel仍被评估为true,而循环不应该完成,除非剪贴板内有东西。这怎么可能? 澄清:这个结构是为了回答问题:SendEvent ^{ins} isn't copying content to the clipboard 因此,是的,我知道循环剪贴板不被视为可靠的做法。但除了采用这种结构之外别无选择。

1 个答案:

答案 0 :(得分:1)

while循环期望表达式,clipboard =不是表达式。试试这个:

clipboard := ""
while( StrLen(clipboard) < 1 )
{
    Send, ^{ins}
    Sleep, 50
}
MsgBox % ClipBoard