Issue with conditional up/down hotkeys

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
RPAMania
Posts: 2
Joined: 08 Aug 2020, 05:20

Issue with conditional up/down hotkeys

Post by RPAMania » 16 Mar 2024, 16:26

The following code should, as I understand the documentation, allow Win-R down event to pass through, causing the Run dialog to be displayed. However, that doesn't happen. It's only when the condition returns false for both the down and up events that the down event gets passed through.

The only place in docs that I can find to possibly apply here is "Limitations: ... 2) An "Up" hotkey without a normal/down counterpart hotkey will completely take over that key to prevent it from getting stuck down.". In this case, though, it seems there's a matching down counterpart with a common conditional function.

Is there something I'm overlooking?

Code: Select all

#Requires AutoHotkey v1.1
#if condfunc()
hotkey, if, condfunc()

fn := func("triggerfunc")
hotkey, #r, % fn ; Win-R down
hotkey, #r up, % fn ; Win-R up

hotkey, if
return

condfunc()
{
  condition := a_thishotkey == "#r up"

  if (a_thishotkey == "#r")
  {
    tooltip % "Returning " condition
  }

  return condition
}

triggerfunc()
{
  if (a_thishotkey == "#r")
  {
    msgbox % a_thishotkey ; Never displayed, so the down event should get passed through
  }
}
In the script's Key history view I can even see that capturing Win-R down is disabled, but the event remains nowhere to be seen.

Code: Select all

#=Disabled via #IfWinActive/Exist

Code: Select all

5B  15B	 	d	0.52	LWin           	
52  013	#	d	0.00	r              	
52  013	h	u	0.16	r              	
5B  15B	 	u	0.11	LWin

Rohwedder
Posts: 7656
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Issue with conditional up/down hotkeys

Post by Rohwedder » 17 Mar 2024, 02:02

Hallo,
I've simplified the scenario:

Code: Select all

#IF A_ThisHotkey = "#r Up"
#r::SoundBeep, 4000, 20 ; never executed
#r Up::SoundBeep, 1000, 20
#IF
I assume that the condition A_ThisHotkey = "#r Up" is only recognized as false if the hotkey #f has already been triggered.
Only then does A_ThisHotkey get the value "#r". The execution of the hotkey is suppressed but it is too late to prevent its triggering, of course.

Code: Select all

#IF A_ThisHotkey = "#r Up"
#r::SoundBeep, 4000, 20 ; never executed
#r Up::SoundBeep, 1000, 20
#IF
~#r::Return
This has the desired behavior.

Post Reply

Return to “Ask for Help (v1)”