Positional hotkeys when registered inside a function?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
highend
Posts: 47
Joined: 24 Nov 2014, 16:57

Positional hotkeys when registered inside a function?

Post by highend » 23 May 2023, 07:32

Hi,

I have function that is called every 5 seconds (via SetTimer) that checks if the belonging .ini file was modified and if yes, rereads the values.
The (de-) registration of the hotkey takes place inside that function

E.g.:

Code: Select all

GetIniFileValues(file) {
    static iniLastHotkey := ""

    iniHotkey := IniRead(file, "General", "Hotkey", "")
    if (iniHotkey = "")
        iniHotkey := "^Q"

    if (iniLastHotkey != "" && iniHotkey != iniLastHotkey) {
        Hotkey iniLastHotkey, Hotkey_ShowGui, "Off"
    }

    Hotkey iniHotkey, Hotkey_ShowGui, "On"
    iniLastHotkey := iniHotkey

    ; ... do more stuff
}
While (part) of the .ini looks like this:

Code: Select all

[General]
; The hotkey to invoke the drop-down menu
; # = Win
; ! = Alt
; ^ = Ctrl
; + = Shift
; Default = ^Q (Ctrl+Q)
Hotkey=^Q
and the Hotkey_ShowGui function looks like this:

Code: Select all

Hotkey_ShowGui(ThisHotkey) {
    if (WinActive("ahk_class " C["DialogClass"]) {
        ; ... do stuff
    }
    return
}
Can anybody show me where (and how) to add the positional requirement so that the hotkey that is read from the .ini file is only active with the requirement:
HotIf WinActive("ahk_class " C["DialogClass"])

I just can't get it to work...
Last edited by highend on 23 May 2023, 09:06, edited 1 time in total.

WKen
Posts: 200
Joined: 21 Feb 2023, 00:01

Re: Positional hotkeys when registered inside a function?

Post by WKen » 23 May 2023, 08:41

HotIf WinActive("ahk_class" C["DialogClass"])
A space? Need hotkey.

Code: Select all

#HotIf WinActive("ahk_class " C["DialogClass"])
       F3::GetIniFileValues(file)
#HotIf

highend
Posts: 47
Joined: 24 Nov 2014, 16:57

Re: Positional hotkeys when registered inside a function?

Post by highend » 23 May 2023, 09:09

?

I don't want to register a static hotkey and it's not outside of a function...

WKen
Posts: 200
Joined: 21 Feb 2023, 00:01

Re: Positional hotkeys when registered inside a function?

Post by WKen » 23 May 2023, 10:15

That's abbreviated. Use Loop + WinWaitActive?
https://www.autohotkey.com/docs/v2/lib/WinWaitActive.htm

Post Reply

Return to “Ask for Help (v2)”