need help to save gui hotkeys after close for next re-open (script included)

Get help with using AutoHotkey and its commands and hotkeys
NewberEnerNeeder1
Posts: 22
Joined: 26 Mar 2019, 06:06

need help to save gui hotkeys after close for next re-open (script included)

10 Jun 2019, 10:57

After i set the hot key i would like it to save on close so it remembers for the next time i open it.

can anyone help with this?

Code: Select all



#Persistent
#SingleInstance Force
#NoEnv


Gui, New,
Gui, Add, Hotkey,w300 gOneHotkey VHkey
Gui, Show
Return


OneHotkey:
HClear:=Hkey
If (StateHKey="On")
{
	HKeyOldest:=HClear
	StateHKey=Off
	Hotkey, %HKeyOldmost%, OFF, UseErrorLevel OFF
}
else
{
	HKeyOldmost:=HClear
	StateHKey=On
	Hotkey, %HKeyOldest%, OFF, UseErrorLevel OFF
}
Msgbox %HKeyOldest%`n%HKeyOldmost% 
Hotkey, %HKey%, Hello, UseErrorLevel ON
Return
	

Hello:
Msgbox Hello
Return

GuiClose:
ExitApp




i found the script here autohotkey.com/boards/viewtopic.php?t=23288
User avatar
TheDewd
Posts: 1446
Joined: 19 Dec 2013, 11:16
Location: USA

Re: need help to save gui hotkeys after close for next re-open (script included)

10 Jun 2019, 15:04

Code: Select all

#SingleInstance Force
#Persistent
#NoEnv

IniRead, MyHK, settings.ini, Application, MyHotkey

Gui, Margin, 8, 8
Gui, Add, Hotkey, w300 gOneHotkey VHkey, % MyHK
Gui, Show, AutoSize, Example
return

OneHotkey:
	HClear := Hkey

	If (StateHKey = "On") {
		HKeyOldest := HClear
		StateHKey := "Off"
		Hotkey, %HKeyOldmost%, OFF, UseErrorLevel OFF
	} Else {
		HKeyOldmost := HClear
		StateHKey := "On"
		Hotkey, %HKeyOldest%, OFF, UseErrorLevel OFF
	}

	MsgBox, %HKeyOldest%`n%HKeyOldmost%
	Hotkey, %HKey%, Hello, UseErrorLevel ON
return

Hello:
	Msgbox, Hello
return

GuiClose:
	IniWrite, % Hkey, settings.ini, Application, MyHotkey
	ExitApp
return
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
NewberEnerNeeder1
Posts: 22
Joined: 26 Mar 2019, 06:06

Re: need help to save gui hotkeys after close for next re-open (script included)

10 Jun 2019, 17:55

ty for the help.

i tried the script and it did work! it saved the hotkey on the close.

i tried to see if i can make a 2nd hotkey and got that to work.

but

then i tested it in a couple of ways.

1) it saved when i close it but then the 2nd time i close it... it goes back to default like no hotkey was used.

2) after i close it and re-open it the hot keys it remembers dont work. the hot key does not trigger the "hello" msgbox

any ideas?







Code: Select all

#SingleInstance Force
#Persistent
#NoEnv


IniRead, MyHK, settings.ini, Application, MyHotkey
IniRead, MyHK2, settings.ini, Application, MyHotkey2



Gui, Margin, 8, 8
Gui, Add, Hotkey, w300 gOneHotkey VHkey, % MyHK
Gui, Add, Hotkey, w300 gOneHotkey2 VHkey2, % MyHK2
Gui, Show, AutoSize, Example
return

OneHotkey:
	HClear := Hkey

	If (StateHKey = "On") {
		HKeyOldest := HClear
		StateHKey := "Off"
		Hotkey, %HKeyOldmost%, OFF, UseErrorLevel OFF
	} Else {
		HKeyOldmost := HClear
		StateHKey := "On"
		Hotkey, %HKeyOldest%, OFF, UseErrorLevel OFF
	}

	MsgBox, %HKeyOldest%`n%HKeyOldmost%
	Hotkey, %HKey%, Hello, UseErrorLevel ON
return

Hello:
	Msgbox, Hello
return







OneHotkey2:
	HClear2 := Hkey2

	If (StateHKey2 = "On") {
		HKeyOldest2 := HClear2
		StateHKey2 := "Off"
		Hotkey, %HKeyOldmost2%, OFF, UseErrorLevel OFF
	} Else {
		HKeyOldmost2 := HClear2
		StateHKey2 := "On"
		Hotkey, %HKeyOldest2%, OFF, UseErrorLevel OFF
	}

	MsgBox, %HKeyOldest2%`n%HKeyOldmost2%
	Hotkey, %HKey2%, Hello2, UseErrorLevel ON
return

Hello2:
	Msgbox, Hello2
return










GuiClose:
        
	IniWrite, % Hkey2, settings.ini, Application, MyHotkey2
	IniWrite, % Hkey, settings.ini, Application, MyHotkey
	ExitApp
return

User avatar
YoucefHam
Posts: 344
Joined: 24 Aug 2015, 12:56
Facebook: https://fb.me/YoucefHamDz
Google: [email protected]
GitHub: YoucefHam
Location: Algeria
Contact:

Re: need help to save gui hotkeys after close for next re-open (script included)

10 Jun 2019, 18:33

try this

Code: Select all

#SingleInstance Force
#Persistent
#NoEnv


IniRead, HKey, settings.ini, Application, MyHotkey
if (HKey <> "ERROR") or (HKey <> "")
    Hotkey, % HKey, Hello, UseErrorLevel ON
IniRead, HKey2, settings.ini, Application, MyHotkey2
if (HKey2 <> "ERROR") or (HKey2 <> "")
    Hotkey, % HKey2, Hello2, UseErrorLevel ON

Gui, Margin, 8, 8
Gui, Add, Hotkey, w300 gOneHotkey VHkey, % HKey
Gui, Add, Hotkey, w300 gOneHotkey2 VHkey2, % HKey2
Gui, Show, AutoSize, Example
return

GuiClose:
IniWrite, % Hkey, settings.ini, Application, MyHotkey
IniWrite, % Hkey2, settings.ini, Application, MyHotkey2
ExitApp
return

OneHotkey:
	HClear := Hkey

	If (StateHKey = "On") {
		HKeyOldest := HClear
		StateHKey := "Off"
		Hotkey, %HKeyOldmost%, OFF, UseErrorLevel OFF
	} Else {
		HKeyOldmost := HClear
		StateHKey := "On"
		Hotkey, %HKeyOldest%, OFF, UseErrorLevel OFF
	}

	MsgBox, %HKeyOldest%`n%HKeyOldmost%
	Hotkey, %HKey%, Hello, UseErrorLevel ON
return

Hello:
	Msgbox, Hello
return

OneHotkey2:
	HClear2 := Hkey2

	If (StateHKey2 = "On") {
		HKeyOldest2 := HClear2
		StateHKey2 := "Off"
		Hotkey, %HKeyOldmost2%, OFF, UseErrorLevel OFF
	} Else {
		HKeyOldmost2 := HClear2
		StateHKey2 := "On"
		Hotkey, %HKeyOldest2%, OFF, UseErrorLevel OFF
	}

	MsgBox, %HKeyOldest2%`n%HKeyOldmost2%
	Hotkey, %HKey2%, Hello2, UseErrorLevel ON
return

Hello2:
	Msgbox, Hello2
return

:wave: There is always more than one way to solve a problem. ;)

Return to “Ask For Help”

Who is online

Users browsing this forum: anv, Bing [Bot], effel, Google [Bot], JAutohotkey, mikeyww, return, teadrinker and 51 guests