Question about using HotIF

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Maxsteinfeld
Posts: 87
Joined: 25 Jun 2017, 02:18

Question about using HotIF

Post by Maxsteinfeld » 24 Mar 2023, 09:35

Hi
i have a simple qestion about the script beyond:
i want to start a hotkey (Pause::) via hotkey (^F12::)

Code: Select all

#Requires AutoHotkey v2.0
#SingleInstance Force
#HotIf winexist('ahk_exe explorer.exe')
		^F12::
		{
			msgbox 'go',,'T1'
			send '{Pause}'
			return
		}
		Pause::
		{
			msgbox 'Pause',,'T1'
			return
		}
#HotIF
if explorer is active:
pushing ^F12 does not start Pause-Hotkey
pushing Key 'Pause' itself starts the Pause-Hotkey ?
why doesn't the pause script start?
need help
M.

User avatar
Datapoint
Posts: 296
Joined: 18 Mar 2018, 17:06

Re: Question about using HotIF

Post by Datapoint » 24 Mar 2023, 10:58

To call a hotkey you can define a named function for the pause hotkey.

Code: Select all

#Requires AutoHotkey v2.0
^F12::
{
	MsgBox A_ThisHotkey " was pressed.", "^F12"
	PauseHotkey(A_ThisHotkey)
}
Pause::
	PauseHotkey(hk) ; https://www.autohotkey.com/docs/v2/Hotkeys.htm#Function
	{
		MsgBox hk " was pressed.", "Pause"
	}

Maxsteinfeld
Posts: 87
Joined: 25 Jun 2017, 02:18

Re: Question about using HotIF

Post by Maxsteinfeld » 24 Mar 2023, 11:16

@Datapoint
Thx
but your code does not match my problem
pushing ^F12 does not start Pause-Hotkey (msgbox 'Pause',,'T1')
while explorer.exe is active
if I omit the HotIf-brackets
everything works as it should:

Code: Select all

^F12::
		{
			msgbox 'go',,'T1'
			send '{Pause}'
			return
		}
		Pause::
		{
			msgbox 'Pause',,'T1'
			return
works but not if i add the HotIf parts

User avatar
Datapoint
Posts: 296
Joined: 18 Mar 2018, 17:06

Re: Question about using HotIF

Post by Datapoint » 24 Mar 2023, 11:24

Hmm, I'm not sure then. It seemed to work for me.
Maxsteinfeld wrote:
24 Mar 2023, 11:16
while explorer.exe is active
Note, your code above uses WinExist, not WinActive.

Post Reply

Return to “Ask for Help (v2)”