Help to save a hotkey and remember the letters Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
XtiiGmA
Posts: 26
Joined: 21 Apr 2021, 10:22

Help to save a hotkey and remember the letters

07 May 2021, 11:25

Hello, sorry for my English.
I have 2 problems with this:
1. As you can see it is a simple box where I put a key like hotkey (example "E") in the AHK variable of the hotkey, and any letters in Key1 and Key2, and when pressing the Save button it saves it.
Then when pressing "E" for example in notepad, Exit key1, wait 1 second and Key2, which we put.
I tried to put% ahk%, but I get an error.

2. Is it possible that when I put the Hotkeys and put save, the program remembers the Hotkeys that I put?
So once I close the program and reopen it, can I remember the HotKeys that I set earlier?

Thanks!!!

Code: Select all

#SingleInstance, force

Gui, Add, Text,y10,AHK
Gui, Add, Text,,KEY1
Gui, Add, Text,,KEY2
Gui, Add, Hotkey, ym vahk ,
Gui, Add, Hotkey,vKey1,
Gui, Add, Hotkey,vKey2,
Gui, Add, Button,ym,Save
Gui, Add, Button,x+5,Close
Gui, show,,Hi!
return

ButtonSave:
Gui, Submit, NoHide
return

%ahk%::     ;HELP ME HERE!!!
SendInput, %Key1%
Sleep, 1000
SendInput, %Key2%
return

ButtonClose:
ExitApp
return
User avatar
mikeyww
Posts: 26857
Joined: 09 Sep 2014, 18:38

Re: Help to save a hotkey and remember the letters

07 May 2021, 12:35

Yes. You can use IniWrite to save your settings into a text file.

The Hotkey command can help you enable your new hotkey routine. You just change your routine so that it has a subroutine label (name). You then specify that label in your Hotkey command (see Example #1).
XtiiGmA
Posts: 26
Joined: 21 Apr 2021, 10:22

Re: Help to save a hotkey and remember the letters

07 May 2021, 12:56

Hi mikeyww, thanks for replying.

Code: Select all

Hotkey, $%ahk%
SendInput, %Key1%
Sleep, 1000
SendInput, %Key2%
return
I have tried this and when I press Save, nothing happens. :cry:
User avatar
mikeyww
Posts: 26857
Joined: 09 Sep 2014, 18:38

Re: Help to save a hotkey and remember the letters

07 May 2021, 12:59

If you click "Hotkey" in the script that you posted, you will see the proper syntax. Example #1 on that page provides you with, well, an example. You can start with exactly the same example, and then replace the parts so that it matches your script. When you first use the Hotkey command, you would include the name of your labeled subroutine that should execute when the hotkey is triggered.
XtiiGmA
Posts: 26
Joined: 21 Apr 2021, 10:22

Re: Help to save a hotkey and remember the letters

07 May 2021, 13:19

Works! Thank you so much for your patience...

Code: Select all

ButtonSave:
Gui, Submit, NoHide
Hotkey, $%ahk%, Comand
return

Comand:
SendInput, %Key1%
Sleep, 1000
SendInput, %Key2%
return
Now could you help me that when I close the window and start it again, does it remember the hotkeys that I put previously?
User avatar
mikeyww
Posts: 26857
Joined: 09 Sep 2014, 18:38

Re: Help to save a hotkey and remember the letters  Topic is solved

07 May 2021, 13:53

Code: Select all

#SingleInstance Force
ini := StrReplace(A_ScriptFullPath, ".ahk", ".ini")
Gui, Add, Text, y10,AHK
Gui, Add, Text,, KEY1
Gui, Add, Text,, KEY2
Gui, Add, Hotkey, ym vahk
Gui, Add, Hotkey,vKey1
Gui, Add, Hotkey,vKey2
Gui, Add, Button,ym,Save
Gui, Add, Button,x+5,Close
IniRead, ahk, %ini%, Main, ahk
IniRead, Key1, %ini%, Main, Key1
IniRead, Key2, %ini%, Main, Key2
GuiControl,, ahk, %ahk%
GuiControl,, Key1, %Key1%
GuiControl,, Key2, %Key2%
Gui, Show,, Hi!
OnExit("done")
Return

ButtonSave:
Gui, Submit, NoHide
Hotkey, $%ahk%, Comand
Return

Comand:
SendInput, %Key1%
Sleep, 1000
SendInput, %Key2%
Return

ButtonClose:
ExitApp

done(ExitReason, ExitCode) {
 Global
 Gui, Submit
 IniWrite, %ahk%, %ini%, Main, ahk
 IniWrite, %Key1%, %ini%, Main, Key1
 IniWrite, %Key2%, %ini%, Main, Key2
 SoundBeep, 1500
}
XtiiGmA
Posts: 26
Joined: 21 Apr 2021, 10:22

Re: Help to save a hotkey and remember the letters

07 May 2021, 14:00

wow! Thank you very much, you are an angel ... it works!
XtiiGmA
Posts: 26
Joined: 21 Apr 2021, 10:22

Re: Help to save a hotkey and remember the letters

07 May 2021, 16:12

@mikeyww

Hello friend, I found another way to do it, I would just have to create a gold update button and that's it.
But I don't understand why here:
Gui, Add, Edit, x42 y19 w300 h120 viniinfo,% iniinfo%
The variable is repeated both with vIniInfo and another with %%

Code: Select all

#SingleInstance, force

myinipath = C:\Users\Thom\Desktop\initest.ini

f1::
Gui, destroy
Gui, Add, Button, x72 y159 w100 h30 greadtheini, Update
Gui, Add, Button, x222 y159 w100 h30 gsavetoini, save
Gui, Add, Edit, x42 y19 w300 h120 viniinfo, %iniinfo% ;"WHY?"
Gui, Show, x769 y389 h223 w400, test window ini
Return

savetoini:
gui, submit
IniWrite, %iniinfo%, %myinipath%, myinfo, info1
return

readtheini:
IniRead, iniinfo, %myinipath%, myinfo, info1
GuiControl,, iniinfo, %iniinfo%
Return

GuiClose:
Gui, destroy
Return
User avatar
mikeyww
Posts: 26857
Joined: 09 Sep 2014, 18:38

Re: Help to save a hotkey and remember the letters

07 May 2021, 16:25

I like it when the person who posted the question discovers the answer to the puzzle! It looks like you did it here, too.

Regarding your question, the "v" is, in essence, the output (newly assigned) variable, where the other variable is like an input variable or the default starting text for the edit field. Yes, they can be the same, as in your example.

Code: Select all

#SingleInstance Force
myinipath = %A_Desktop%\initest.ini
Gui, Add, Edit  , x42  y19  w310 h120 viniinfo   , %iniinfo%
Gui, Add, Button, x72  y+20 w100 h30  greadtheini, Update
Gui, Add, Button, x222 yp   wp   hp   gsavetoini , save
Gosub, readtheini
Gosub, F1
F1::Gui, Show, x769 y389 h210 w400, test window ini

savetoini:
Gui, Submit
IniWrite, %iniinfo%, %myinipath%, myinfo, info1
Return

readtheini:
If !FileExist(myinipath)
 Return
IniRead, iniinfo, %myinipath%, myinfo, info1
GuiControl,, iniinfo, %iniinfo%
Return

GuiClose:
Gui, Hide
Return
XtiiGmA
Posts: 26
Joined: 21 Apr 2021, 10:22

Re: Help to save a hotkey and remember the letters

07 May 2021, 18:35

Thank you, @mikeyww
Friend I have this problem, I am making my own charts to better understand iniRead and iniWrite, Everything ok when the Read button, But when I try to enter a new variable, the document.ini appears blank.
could you help me please?

Code: Select all

F4::
Gui, Add, Edit, vMostrar, %Texto%
Gui, Add, Button, gButton1, Read
Gui, Add, Button, gButton2, Writte
Gui, show,,
return

Button1:
	Gui, Submit, NoHide
	IniRead, Texto, C:\Folder\File.INI, Fruits, Name1
	GuiControl,,Mostrar, %Texto% 
	return

Button2:
	Gui, Submit, NoHide
	IniWrite, %Texto%, C:\Folder\File.INI, Fruits, Name5
	return

GuiClose:
ExitApp
return
XtiiGmA
Posts: 26
Joined: 21 Apr 2021, 10:22

Re: Help to save a hotkey and remember the letters

07 May 2021, 18:39

I found the answer. XD

is

Code: Select all

IniWrite, %Mostrar%, C:\Folder\File.INI, Fruits, Name5

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ntepa, vanove and 172 guests