Problem using If statement

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
memberAHK
Posts: 4
Joined: 30 Nov 2017, 01:06

Problem using If statement

30 Nov 2017, 01:31

I am very new to AHK programming, so please bear with me.

In the following code, when text can be copied to Clipboard, MsgBox displays the text. However, it does not work ("Hi" not displayed) if there is no text copied (so Clipboard is null). Any suggestion? Thanks.

F10::
Clipboard := ""
Send ^a
Send ^c
ClipWait
strTM := Clipboard
if (Clipboard = "") {
MsgBox Hi
}
else {
MsgBox %strTM%
}
return
Rohwedder
Posts: 7768
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Problem using If statement

30 Nov 2017, 02:02

Hallo,
try:

Code: Select all

F10::
Clipboard := ""
Send ^a
Send ^c
ClipWait,1
strTM = %Clipboard%
if (strTM = "") {
MsgBox Hi
}
else {
MsgBox %strTM%
}
return
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: Problem using If statement

30 Nov 2017, 02:14

You're going to kick yourself, but it's hanging at the ClipWait command. When nothing is copied to the clipboard, ClipWait does its job and waits for something to be in the clipboard before proceeding. Remove the ClipWait command and the hotkey works as you designed it.
memberAHK
Posts: 4
Joined: 30 Nov 2017, 01:06

Re: Problem using If statement

30 Nov 2017, 02:19

Problem solved. Thanks folks.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 241 guests