User defined "Set Hotkeys" Menu (how to?) Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Re: User defined "Set Hotkeys" Menu (how to?)

23 Apr 2023, 14:51

Datapoint wrote:
23 Apr 2023, 12:57
Try adding "*" when calling the hotkey function.

Code: Select all

StoredHotkey := "F5"
Hotkey "*" StoredHotkey , FunctionName, "On"
MyHotkey.AssignedKey := IniRead(A_ScriptDir "\Data\INI-Files\Hotkeys.ini", "Hotkeys", MyHotkey.INI_Key)

this one?
User avatar
Datapoint
Posts: 308
Joined: 18 Mar 2018, 17:06

Re: User defined "Set Hotkeys" Menu (how to?)

23 Apr 2023, 17:10

Untested, but if you were to add it to my previous post, you would add this line to the OK_Click function.
MyHotkey.AssignedKey := "*" MyHotkey.AssignedKey
That will add * to the start of the hotkey right before it is saved to INI and before the hotkey is activated.

Code: Select all

    ...
	; Enable new hotkeys and save to INI
    MyGui.Submit()
    for i, MyHotkey in SavedHotkeys
    {
        MyHotkey.AssignedKey := MyHotkey.GUI_CtrlObj.Value
        if MyHotkey.AssignedKey = ""
            continue
		MyHotkey.AssignedKey := "*" MyHotkey.AssignedKey ; <-- always adds * to hotkeys before they are activated and saved
        Hotkey MyHotkey.AssignedKey, MyHotkey.Function, "On"
        IniWrite MyHotkey.AssignedKey, A_ScriptDir "\Hotkeys.ini", "Hotkeys", MyHotkey.INI_Key
    }
	...
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Re: User defined "Set Hotkeys" Menu (how to?)

23 Apr 2023, 17:21

Datapoint wrote:
23 Apr 2023, 17:10
Untested, but if you were to add it to my previous post, you would add this line to the OK_Click function.
MyHotkey.AssignedKey := "*" MyHotkey.AssignedKey
That will add * to the start of the hotkey right before it is saved to INI and before the hotkey is activated.

Code: Select all

    ...
	; Enable new hotkeys and save to INI
    MyGui.Submit()
    for i, MyHotkey in SavedHotkeys
    {
        MyHotkey.AssignedKey := MyHotkey.GUI_CtrlObj.Value
        if MyHotkey.AssignedKey = ""
            continue
		MyHotkey.AssignedKey := "*" MyHotkey.AssignedKey ; <-- always adds * to hotkeys before they are activated and saved
        Hotkey MyHotkey.AssignedKey, MyHotkey.Function, "On"
        IniWrite MyHotkey.AssignedKey, A_ScriptDir "\Hotkeys.ini", "Hotkeys", MyHotkey.INI_Key
    }
	...

Thanks for Reply me again :)

hmm it looks kinda different, i am still using your first version

Code: Select all

OK_Click(*)
{
    ; Disable old hotkeys
    for i, MyHotkey in SavedHotkeys
        if MyHotkey.AssignedKey != ""
            Hotkey MyHotkey.AssignedKey, "Off"
    Saved := MyGui.Submit()
    ; Enable new hotkeys and save to INI
    for i, MyHotkey in SavedHotkeys
    {
        MyHotkey.AssignedKey := Saved.%MyHotkey.GUI_Var%
        Hotkey MyHotkey.AssignedKey, MyHotkey.Function
        IniWrite MyHotkey.AssignedKey, A_ScriptDir "\Data\INI-Files\Hotkeys.ini", "Hotkeys", MyHotkey.INI_Key
    }
}
There are different additional Commands, and as we all know a single wrong ! or := can fuck everything :D so i am sorry if i repeat to often...

yours got a "On" after function and i got a Saved.%MyHotkey.GUI_Var% where yours got "*" MyHotkey.AssignedKey ;
i totaly dont understand your code :( i am just happy u shared it with me :D
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Re: User defined "Set Hotkeys" Menu (how to?)

23 Apr 2023, 17:26

@Datapoint here is the full Script Part cuse u can probably read it

Code: Select all

; ------ Hotkey-Set Code by "Datapoint" starts here ------

; Use this data to keep track of each hotkey / function / GUI info ; Hotkey Set Code by Datapoint
SavedHotkeys := []

SavedHotkeys.Push( {Function:   DS4ControllerFunction
                  , INI_Key:    "DS4CF_Hotkey"
                  , GUI_Text:   "DS4Controller Function On/Off"
                  , GUI_Var:    "DS4CF"} )
                  
SavedHotkeys.Push( {Function:   XboxControllerFunction
                  , INI_Key:    "XBXCF_Hotkey"
                  , GUI_Text:   "XboxController Function On/Off"
                  , GUI_Var:    "XBXCF"} )

SavedHotkeys.Push( {Function:   RapidFireFunction
                  , INI_Key:    "RFF_Hotkey"
                  , GUI_Text:   "RapidFire On/Off"
                  , GUI_Var:    "RFF"} )

SavedHotkeys.Push( {Function:   TimeGlitchFunction
                  , INI_Key:    "TGF_Hotkey"
                  , GUI_Text:   "TimeGlitch Hotkey"
                  , GUI_Var:    "TGF"} )

SavedHotkeys.Push( {Function:   AutoClickerFunction
                  , INI_Key:    "ACF_Hotkey"
                  , GUI_Text:   "AutoClicker Hotkey"
                  , GUI_Var:    "ACF"} )

SavedHotkeys.Push( {Function:   AntiAFKFunction
                  , INI_Key:    "AAFKF_Hotkey"
                  , GUI_Text:   "AntiAFK Hotkey"
                  , GUI_Var:    "AAFKF"} )

SavedHotkeys.Push( {Function:   ExitScript
                   , INI_Key:    "Exit_Hotkey"
                   , GUI_Text:   "Exit Script"
                   , GUI_Var:    "SC_Exit"} )

 ; Create a GUI ; Hotkey Set Code by Datapoint
MyGui := Gui(, "Set Hotkeys")

HK_NOT_SET := false

; Read saved hotkeys
for i, MyHotkey in SavedHotkeys
{
    MyHotkey.AssignedKey := IniRead(A_ScriptDir "\Data\INI-Files\Hotkeys.ini", "Hotkeys", MyHotkey.INI_Key)

    MyGui.AddText("x10", MyHotkey.GUI_Text)
    MyGui.AddHotkey("x+10 v"  MyHotkey.GUI_Var, MyHotkey.AssignedKey)

    ; If there is a blank hotkey then set HK_NOT_SET to true so the GUI will be opened later
    if MyHotkey.AssignedKey = ""
        HK_NOT_SET := true
    ; else activate the saved hotkey
    else
        Hotkey MyHotkey.AssignedKey, MyHotkey.Function
}

MyGui.Add("Button", "Default x10 w100", "OK").OnEvent("Click", OK_Click)

; Open the GUI if there was a blank hotkey loaded from the INI
if HK_NOT_SET 
    SetHotkeys()
return

SetHotkeys(*)
{
    MyGui.Show()
}

OK_Click(*)
{
    ; Disable old hotkeys
    for i, MyHotkey in SavedHotkeys
        if MyHotkey.AssignedKey != ""
            Hotkey MyHotkey.AssignedKey, "Off"
    Saved := MyGui.Submit()
    ; Enable new hotkeys and save to INI
    for i, MyHotkey in SavedHotkeys
    {
        MyHotkey.AssignedKey := Saved.%MyHotkey.GUI_Var%
        Hotkey MyHotkey.AssignedKey, MyHotkey.Function
        IniWrite MyHotkey.AssignedKey, A_ScriptDir "\Data\INI-Files\Hotkeys.ini", "Hotkeys", MyHotkey.INI_Key
    }
}
ExitScript(*)
{
    ExitApp ; Preset Hotkey (F10) for Exit Script, Fully closes the Script
}

/* Example Hotkeys.ini file contents: (Preset by Tobgun1)

[Hotkeys]
DS4CF_Hotkey=F4
XBXCF_Hotkey=F5
RFF_Hotkey=F6
TGF_Hotkey=F7
ACF_Hotkey=F8
AAFKF_Hotkey=F9
Exit_Hotkey=F10
User avatar
Datapoint
Posts: 308
Joined: 18 Mar 2018, 17:06

Re: User defined "Set Hotkeys" Menu (how to?)

23 Apr 2023, 18:02

MyHotkey.AssignedKey is storing the same thing in both versions of my script. It contains a sting that represents the assigned keys for the hotkey. "^F5" for example. So if you add this line, MyHotkey.AssignedKey := "*" MyHotkey.AssignedKey it changes "^F5" to "*^F5".
Then on the next two lines the hotkey is activated and saved to the INI file. So both the newly activated hotkey and the INI file will contain the "*" option.

Code: Select all

    ...
    for i, MyHotkey in SavedHotkeys
    {
        MyHotkey.AssignedKey := Saved.%MyHotkey.GUI_Var% ; This line gets the keys that were entered into the GUI hotkey control.
        MyHotkey.AssignedKey := "*" MyHotkey.AssignedKey ; This line adds "*" to the assigned key
        Hotkey MyHotkey.AssignedKey, MyHotkey.Function, "On" ; This line activates the hotkey.
        IniWrite MyHotkey.AssignedKey, A_ScriptDir "\Data\INI-Files\Hotkeys.ini", "Hotkeys", MyHotkey.INI_Key ; This is the line that writes the keys to the INI file.
    }
    ...
yours got a "On" after function
I think adding "on" worked better when I was testing. If I recall correctly it activates hotkeys that are disabled, not just newly created ones.
Tobgun1
Posts: 123
Joined: 23 Feb 2023, 07:28

Re: User defined "Set Hotkeys" Menu (how to?)

23 Apr 2023, 19:35

Datapoint wrote:
23 Apr 2023, 18:02
MyHotkey.AssignedKey is storing the same thing in both versions of my script. It contains a sting that represents the assigned keys for the hotkey. "^F5" for example. So if you add this line, MyHotkey.AssignedKey := "*" MyHotkey.AssignedKey it changes "^F5" to "*^F5".
Then on the next two lines the hotkey is activated and saved to the INI file. So both the newly activated hotkey and the INI file will contain the "*" option.

Code: Select all

    ...
    for i, MyHotkey in SavedHotkeys
    {
        MyHotkey.AssignedKey := Saved.%MyHotkey.GUI_Var% ; This line gets the keys that were entered into the GUI hotkey control.
        MyHotkey.AssignedKey := "*" MyHotkey.AssignedKey ; This line adds "*" to the assigned key
        Hotkey MyHotkey.AssignedKey, MyHotkey.Function, "On" ; This line activates the hotkey.
        IniWrite MyHotkey.AssignedKey, A_ScriptDir "\Data\INI-Files\Hotkeys.ini", "Hotkeys", MyHotkey.INI_Key ; This is the line that writes the keys to the INI file.
    }
    ...
yours got a "On" after function
I think adding "on" worked better when I was testing. If I recall correctly it activates hotkeys that are disabled, not just newly created ones.
Thanks a lot! now i understood it ! Worked :) :thumbup: :thumbup: :thumbup: :thumbup:

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: kiwichick, niCode, TAC109, WarlordAkamu67 and 33 guests