help making an app the active window Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
redrum
Posts: 92
Joined: 25 Jan 2015, 22:57

help making an app the active window

Post by redrum » 10 May 2024, 13:48

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?

User avatar
mikeyww
Posts: 27198
Joined: 09 Sep 2014, 18:38

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

Post by mikeyww » 10 May 2024, 13:56

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!

Post Reply

Return to “Ask for Help (v1)”