Page 1 of 1

help making an app the active window

Posted: 10 May 2024, 13:48
by redrum
Having trouble using a hotkey to make an app the active window. Sometimes it works, sometimes it doesn't.

Code: Select all

^j::  ;make Joplin active 
IfWinExist, ahk_exe Joplin.exe
	WinActivate, ahk_exe Joplin.exe
	Sleep, 200
return
But if I change from WinActivate to MsgBox, this works reliably. So AHK is finding the process, but can't reliably activate it.

Code: Select all

^j::  ;make Joplin active 
IfWinExist, ahk_exe Joplin.exe
	MsgBox, Joplin is running!
	Sleep, 200
return
Any suggestions?

Re: help making an app the active window  Topic is solved

Posted: 10 May 2024, 13:56
by mikeyww
Adding the window class may help. Your Sleep probably does nothing to enhance your script. In addition, indentation will not affect whether an AHK command executes.

Code: Select all

#Requires AutoHotkey v1.1.33.11

#If WinExist("ahk_class Chrome_WidgetWin_1 ahk_exe Joplin.exe")
^j::
WinActivate
SoundBeep 1500
Return
#If
The documentation is your friend. When it identifies deprecated commands, I avoid those!