Khalil
Khalil

Reputation: 311

Looping clipboard and errorlevel evaluation not working as expected

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
    }

Problem: ErrorLevel still gets evaluated as true, whereas the loop shouldn't finish unless something came inside the clipboard. How is this possible? Clarification: This construction was made as an attempt to answer question: SendEvent ^{ins} isn't copying content to the clipboard As such, yes I am aware that looping the clipboard is not regarded as a reliable practice. But I have no other alternative than employing such a construction.

Upvotes: 0

Views: 288

Answers (1)

MCL
MCL

Reputation: 4085

While loops expect expressions, clipboard = is no expression. Try this one:

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

Upvotes: 1

Related Questions