New expression format doesn't seem to work

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
radadar
Posts: 4
Joined: 20 Mar 2017, 23:37

New expression format doesn't seem to work

31 Aug 2018, 15:15

I've been away from AHK for a while and I'm trying to get away from the depreciated format but I'm constantly having problems with the new format.

One example:

If I use the new format of

Code: Select all

if WinExist("ahk_class Notepad")
The script moves along as if notepad was open whether or not it is.

If I use the depreciated

Code: Select all

IfWinExit, ahk_class Notepad
Everything works fine.

Any ideas what I'm doing wrong? I'm on AHK version 1.1.30.00

Thanks.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: New expression format doesn't seem to work

31 Aug 2018, 16:06

That doesn't seem likely. The expression you posted will always work. The depreciated version you posted will never work. ;)

Make sure there's no space between WinExist and the open parenthesis. That would make it concatenation, not a function call.

Also make sure you put braces around the block of code the if-statement is intended to affect, if it's more than one line.
User avatar
Scr1pter
Posts: 1272
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: New expression format doesn't seem to work

31 Aug 2018, 16:15

How about
#if WinActive("ahk_class Notepad")
?

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: New expression format doesn't seem to work

31 Aug 2018, 16:43

Scr1pter wrote:How about
#if WinActive("ahk_class Notepad")
?

Regards
Yea,

There is a big difference between:
if and #if

and between
ifWinExist and #ifWinExist

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
radadar
Posts: 4
Joined: 20 Mar 2017, 23:37

Re: New expression format doesn't seem to work

04 Sep 2018, 11:59

FanaticGuru wrote:
Scr1pter wrote:How about
#if WinActive("ahk_class Notepad")
?

Regards
Yea,

There is a big difference between:
if and #if

and between
ifWinExist and #ifWinExist

FG
Sorry I'm confused doesn't the hatch make it a hot key/string. I don't want a hotkey.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: New expression format doesn't seem to work

04 Sep 2018, 12:09

no. # indicates the start of a directive
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: New expression format doesn't seem to work

04 Sep 2018, 13:05

radadar wrote:
FanaticGuru wrote:
Scr1pter wrote:How about
#if WinActive("ahk_class Notepad")
?

Regards
Yea,

There is a big difference between:
if and #if

and between
ifWinExist and #ifWinExist

FG
Sorry I'm confused doesn't the hatch make it a hot key/string. I don't want a hotkey.
When you use the # it is then a script directive that effects all hotkeys below it in the script.

But as to your probem, these two hotkeys act the same for me.

Code: Select all

F12::
	if WinExist("ahk_class Notepad")
		MsgBox NOTEPAD EXIST
	else
		MsgBox NOPE
return

F11::
	IfWinExist, ahk_class Notepad
		MsgBox NOTEPAD EXIST
	else
		MsgBox NOPE
return
Now if you were to do this:

Code: Select all

#if WinExist("ahk_exe Excel.exe")

F12::
	if WinExist("ahk_class Notepad")
		MsgBox NOTEPAD EXIST
	else
		MsgBox NOPE
return

F11::
	IfWinExist, ahk_class Notepad
		MsgBox NOTEPAD EXIST
	else
		MsgBox NOPE
return
Neither hotkey would do anything unless an Excel window exist.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Billykid and 177 guests