MsgBox does not execute alt+F4 for shut down Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
s_adavan
Posts: 62
Joined: 10 Nov 2020, 06:31

MsgBox does not execute alt+F4 for shut down

23 Oct 2021, 21:13

Previously, I had this hotkey, % (<+5) is to close application / window/ shutdown.

Code: Select all

<+5:: Send, !{F4}
I tried adding the MsgBox, so became like this:

Code: Select all

<+5:: 											
	MsgBox, 4, AHK: Close Window, Close the active program? 
	IfMsgBox, No
		Exit
	Else
		Send, !{F4}							
	return
it works fine, to close application/window, but not for shutdown.
After the MsgBox appears and clicked 'Yes', nothing happened, the 'Shut Down Windows' does not appear.

Your help is much appreciated.
Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: MsgBox does not execute alt+F4 for shut down

24 Oct 2021, 01:50

Hallo,
here your scrpt works. But try:

Code: Select all

<+5::
Win := WinActive("A")
MsgBox, 4, AHK: Close Window, Close the active program?
IfMsgBox, No
	Exit
Else
{
	Send, !{F4}
	WinWaitNotActive, ahk_id %Win%,, 1
	IF !ErrorLevel
		Return
	MsgBox, 4, AHK: Close Windows, Shut down?
	IfMsgBox, Yes
		Shutdown, 1
}
return
s_adavan
Posts: 62
Joined: 10 Nov 2020, 06:31

Re: MsgBox does not execute alt+F4 for shut down

24 Oct 2021, 04:33

Hello Rohwedder, thank you for the respond : )

I just tried the script you gave me, it's the same...
after the first MsgBox appeared, I clicked yes, and then nothing happened.

As you said it works on your side,
I tried isolating the mentioned script as a stand-alone-script (for both scripts),
but it's the same ... nothing happened after the first MsgBox...

hm : ( .. strange..
There is nothing impossible to him who will try. -Alexander the Great-
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: MsgBox does not execute alt+F4 for shut down  Topic is solved

24 Oct 2021, 11:03

Code: Select all

<+5::
	active_id := ""  ;  empty the content of this variable
	WinGet, active_id, ID, A	;  retrieves the ID of the active window and puts it into the variable "active_id"	
	WinGetTitle, WinTitle, ahk_id %active_id%			
	MsgBox, 4, AHK: Close Window, Close the active program? 
	IfMsgBox, No
		return ; end of the hotkey's code
	Else
	{
		WinActivate, ahk_id %active_id%
		WinWaitActive, ahk_id %active_id%, , 2 ; wait 2 seconds maximally  until the specified window is active
		if !ErrorLevel
			Send, !{F4}
		Else  ;  the command timed out
		{			
			MsgBox % "Cannot activate """ . WinTitle . """."
				return
		}		
	}
return
s_adavan
Posts: 62
Joined: 10 Nov 2020, 06:31

Re: MsgBox does not execute alt+F4 for shut down

24 Oct 2021, 22:26

I just wanted to report the initial script does work, but not always.
on attempts to shut down - after pressing the hotkey repeatedly, it suddenly comes to work, and will continue to work fine on repeat.
Yet upon restarting the computer, it does not work again.

Hi GEV,
I've just tried your script repeatedly and also on restart, and it works smoothly..
I did not expect, just by adding a MsgBox, a mere one-line script would turn into such a complex situation.
Thank you very much for the help.

Also Rohwedder,
for the assistance, thank you very much.

:)
There is nothing impossible to him who will try. -Alexander the Great-

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Frogrammer and 279 guests