Any idea why this script launches two instances of Paint?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
lkb3
Posts: 73
Joined: 13 Mar 2014, 16:17

Any idea why this script launches two instances of Paint?

06 Sep 2022, 15:44

I have this script compiled to exe and assigned to a key on my keyboard. Every time I hit this key without Snip & Sketch active (so the second section of the code), it launches two instances of MS Paint. Any idea why? I dont' think the issue is the AHK code itself, but rather something with the execution or command from the keyboard, but I just want to double check. Thanks.

Code: Select all

ifwinactive,, Snip & Sketch
{	
	send {alt down}{alt up}
	sleep 20
	Send m
	sleep 20
	Send O 
	;sleep 500
	WinWait ahk_exe OpenWith.exe
	;WinActivate ahk_exe OpenWith.exe
	;SendPlay {Enter}
	ControlSend,,{Enter},ahk_exe OpenWith.exe
	ExitApp
}



	run mspaint
	WinWait ahk_class MSPaintApp
	WinActivate ahk_class MSPaintApp
	sendinput ^v
	ExitApp
[Mod edit: [code][/code] tags added.]
llinfeng
Posts: 86
Joined: 08 Dec 2016, 21:54
Contact:

Re: Any idea why this script launches two instances of Paint?

09 Oct 2023, 08:57

iseahound wrote:
06 Sep 2022, 18:17
try making the hotkey

Code: Select all

$^v:: func()
Adding the dollar sign didn't work in my case. Instead, changing IfWinExist (deprecated) into function calls of WinExist helped.

The problem: I had similar issues with the following code snippet, where a new TOTALCMD.EXE process would get started although there are existing windows/processes for that process and an existing window has been activated.

Code: Select all

; Define a group for looping through existing instances
groupadd , TC_cmd           , ahk_class TTOTAL_CMD
return

; Here, with the updated $-sign, the hotkey (win + 1) still does two things: activate the existing window *AND* launch a new instance :)
$#1:: Gosub win_1_TC

win_1_TC:
IfWinExist ahk_group TC_cmd
    groupactivate, TC_cmd, r
else
   run "C:\Program Files\totalcmd\TOTALCMD.EXE"
return

Solution: rewrite the subroutine as the following, by calling the WinExist function instead.

Code: Select all

win_1_TC:
if (WinExist("ahk_group TC_cmd")) {
    groupactivate, TC_cmd, r
}
else {
    run "C:\Program Files\totalcmd\TOTALCMD.EXE"
}
return
PS: just curious, how old is IfWinExist and when did it get deprecated in AHK 1.X?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: dra3th, Google [Bot], Mateusz53, Rohwedder, Spawnova and 269 guests