WinActivate / WinWaitActive don't work Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
format_c
Posts: 2
Joined: 18 Oct 2018, 11:12

WinActivate / WinWaitActive don't work

18 Oct 2018, 11:36

Hello folks.

I am struggling with the WinActivate and WinWaitActive functions for two days and cannot find out why they don't work.
Here is my script.

Code: Select all

^!o::
#WinActivateForce ; This directive shows no effect.
; I only mentioned it here to show to you that I am aware of it.

if !WinExist("ahk_exe notepad.exe") {
	; I tried it also with cmd.exe and some other simple applications.
	; I get same results when use window titles instead of file names.
	MsgBox Window does not exist. ; This works.
	return
} else {
	MsgBox Window exists. ; This works too.
}

if !WinActive("ahk_exe notepad.exe") {
	MsgBox AHK is able to regonize whether a window is active or not. ; This works.
	WinActivate, "ahk_exe notepad.exe" ; This doesn't work.
} else {
	MsgBox Window already active. ; This works.
}

WinWaitActive, "ahk_exe notepad.exe", , 5 ; This doesn't work.
; If I omit the timeout, the script hangs here.
if Errorlevel
	; It ends allways with a timeout even if the window has been activated manually before timeout.
	MsgBox Timeout
else
	MsgBox Success

return
Can someone tell me what I am doing wrong?

It doesn't work neither on Win7 nor on Win10. AHK version is 1.1.30.00.

Thanks for your help!
eqv
Posts: 55
Joined: 18 Sep 2018, 22:17

Re: WinActivate / WinWaitActive don't work  Topic is solved

18 Oct 2018, 12:09

format_c wrote:
18 Oct 2018, 11:36
Can someone tell me what I am doing wrong?

Thanks for your help!
Commands doesn't need «" "», so:
This is wrong::

Code: Select all

WinWaitActive, "ahk_exe notepad.exe",, 5	;; << check «" "»
if Errorlevel
	MsgBox Timeout
else
	MsgBox Success

Code: Select all

if !WinActive("ahk_exe notepad.exe") {
	MsgBox AHK is able to regonize...
	WinActivate, "ahk_exe notepad.exe"	;; << check «" "»
} else
	MsgBox Window already active.
This is right::

Code: Select all

WinWaitActive, ahk_exe notepad.exe,, 5		;; << 
if Errorlevel
	MsgBox Timeout
else
	MsgBox Success

Code: Select all

if !WinActive("ahk_exe notepad.exe") {
	MsgBox AHK is able to regonize...
	WinActivate, ahk_exe notepad.exe	;; << 
} else
	MsgBox Window already active.
Functions (always have "()"), need «" "».
Commands (don't have "()"), don't need «" "».

Hope it helps,
User avatar
jeeswg
Posts: 5555
Joined: 19 Dec 2016, 01:58
Location: UK

Re: WinActivate / WinWaitActive don't work

18 Oct 2018, 12:45

Code: Select all

;these work:
WinActivate, % "ahk_exe notepad.exe"
WinWaitActive, % "ahk_exe notepad.exe",, 5

;these work also:
WinActivate, ahk_exe notepad.exe
WinWaitActive, ahk_exe notepad.exe,, 5
Cheers.
format_c
Posts: 2
Joined: 18 Oct 2018, 11:12

Re: WinActivate / WinWaitActive don't work

18 Oct 2018, 14:53

Thank you a lot, guys. It works now.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], chelste1824, SOTE and 169 guests