Problem Clearing Hotkeys with GUI Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Problem Clearing Hotkeys with GUI

11 Jun 2019, 14:51

Disclaimer*** I am not very good at AHK. What I would like to have happen in this script below is when I hit ^f it would set templatepreset1 to ^f4 and then ^1 would no longer trigger the choosetemplate1 label. I added in the gosub, refreshhotkeys to attempt to update the hotkeys but I am at a loss on how to disable templatepreset1 and ^1 from triggering the label. In the current script, when I go into view the variables and their contents I see that I did change templatepreset1 to ^4 but for some reason ^1 is still being triggered. What am i missing in order to clear the original hotkey from triggering?

Feel free to point out any other obvious errors. Again I am just learning.

Code: Select all



TemplatePreset1=^1
TemplatePreset2=^2
TemplatePreset3=^3


gui, add, edit, x25 y25 w35 vTemplatePreset1, ^1
gui, add, edit, y+10 w35 vTemplatePreset2, ^2
gui, add, edit, y+10 w35 vTemplatePreset3, ^3

Gui, Show, w500 h500

gosub, refreshhotkeys
return

refreshhotkeys:
Hotkey,%TemplatePreset1%,ChooseTemplate1
Hotkey,%TemplatePreset2%,ChooseTemplate2
Hotkey,%TemplatePreset3%,ChooseTemplate3
gui, submit, nohide
return

^f::
TemplatePreset1=^4
guicontrol, text, TemplatePreset1, ^4
gosub, refreshhotkeys
return


choosetemplate1:
msgbox, template1
return

choosetemplate2:
msgbox, template2
return

choosetemplate3:
msgbox, template3
return
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Problem Clearing Hotkeys with GUI

11 Jun 2019, 15:09

use Gui, Add, Hotkey better then Edit

Code: Select all

TemplatePreset1=^1
TemplatePreset2=^2
TemplatePreset3=^3


gui, add, Hotkey, x25 y25 w350 vTemplatePreset1, ^1
gui, add, Hotkey, y+10 w350 vTemplatePreset2, ^2
gui, add, Hotkey, y+10 w350 vTemplatePreset3, ^3
Gui, Show, w500 h500
gosub, refreshhotkeys
return

GuiClose:
ExitApp

refreshhotkeys:
gui, submit, nohide
Hotkey,%TemplatePreset1%,ChooseTemplate1
Hotkey,%TemplatePreset2%,ChooseTemplate2
Hotkey,%TemplatePreset3%,ChooseTemplate3
return

^f::
gui, submit, nohide
Hotkey, %TemplatePreset1%, Off
TemplatePreset1=^4
guicontrol,, TemplatePreset1, ^4
gosub, refreshhotkeys
return


choosetemplate1:
msgbox, template1
return

choosetemplate2:
msgbox, template2
return

choosetemplate3:
msgbox, template3
return
:wave: There is always more than one way to solve a problem. ;)
doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Re: Problem Clearing Hotkeys with GUI

11 Jun 2019, 16:07

Thanks for helping out! I prefer the edits so I can put in mouse clicks and tab etc. The hotkey command doesnt seem to accept those (if you have solutions id love to hear them!). It seems like my issue was mostly in the turning off the original hotkey and the ordering of putting the new one in so I will play around with that. Also, I don't know why I can't understand when to gui, submit, nohide whether its before or after the code... keeps confusing me!
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Problem Clearing Hotkeys with GUI

11 Jun 2019, 16:22

here an example to understand Gui, Submit, NoHide

Code: Select all

Gui, Add, edit, w120 vMyVar1, Hello
Gui, Add, edit, w120 vMyVar2, World
Gui, Add, Button, w120 gMsgOut1, Say
Gui, Add, Button, w120 gMsgOut2, Say2
Gui, show
return

GuiClose:
ExitApp

MsgOut1:
Gui, Submit, NoHide ;get all gui controls values
MsgBox, % MyVar1 " " MyVar2
MyVar1 := MyVar2 := ""
return


MsgOut2:
MsgBox, % MyVar1 " " MyVar2
return
:wave: There is always more than one way to solve a problem. ;)
doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Re: Problem Clearing Hotkeys with GUI

12 Jun 2019, 09:03

In my actual code have implemented what you suggested with some success but I am have a problem where if the hotkey becomes blank (for example the user manages to set the hotkey field to none and then click save/submit) then there is no coming back the way we have this written. It tells me Error: "" Is not a valid key name and points to where the hotkeys are first initialized.

I just don't understand why when we change the contents of the hotkey and submit it still allows for the original hotkey to be pressed as well as the new one. This seems very illogical to me. To have to work around it with offs and on's is creating very large scale issues in my code.

Any other suggestions?

edit: If you have none, another question I have is why can't a hotkey after it has been initialized to something be set to blank without getting this same error as above?
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Problem Clearing Hotkeys with GUI

12 Jun 2019, 09:53

use this

Code: Select all

refreshhotkeys:
gui, submit, nohide
if (TemplatePreset1 <> "")
	Hotkey,%TemplatePreset1%,ChooseTemplate1
if (TemplatePreset2 <> "")
	Hotkey,%TemplatePreset2%,ChooseTemplate2
if (TemplatePreset3 <> "")
	Hotkey,%TemplatePreset3%,ChooseTemplate3
return
:wave: There is always more than one way to solve a problem. ;)
doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Re: Problem Clearing Hotkeys with GUI

12 Jun 2019, 10:11

First of all, thank you so much for your help so far. I really am grateful.

Second, with your adjustments heres what I have. You can try it for yourself and tell me whats going on still. If you hit ^f and change the hotkey to ^4 it works. Then if you hit ^g to test an empty hotkey it also works. The problem is if you go to change it back to ^f it gives the nonexistent hotkey error on the line hotkey, %templatepreset1%, off. This translates to the user only being able to update the box once but I would like unlimited changes.

Code: Select all

TemplatePreset1=^1
TemplatePreset2=^2
TemplatePreset3=^3

gui, add, Hotkey, x25 y25 w350 vTemplatePreset1, ^1
gui, add, Hotkey, y+10 w350 vTemplatePreset2, ^2
gui, add, Hotkey, y+10 w350 vTemplatePreset3, ^3
gui,add, button, ,hello

Gui, Show, w500 h500
gosub, refreshhotkeys
return

GuiClose:
ExitApp

refreshhotkeys:
gui, submit, nohide
if (TemplatePreset1 <> "")
	Hotkey,%TemplatePreset1%,ChooseTemplate1
if (TemplatePreset2 <> "")
	Hotkey,%TemplatePreset2%,ChooseTemplate2
if (TemplatePreset3 <> "")
	Hotkey,%TemplatePreset3%,ChooseTemplate3
return

^f::
gui, submit, nohide
Hotkey, %TemplatePreset1%, Off
TemplatePreset1=^4
guicontrol,, TemplatePreset1, ^4
gosub, refreshhotkeys
return

^g::
gui, submit, nohide
Hotkey, %TemplatePreset1%, Off
TemplatePreset1=
guicontrol,, TemplatePreset1,
gosub, refreshhotkeys
return


choosetemplate1:
msgbox, template1
return

choosetemplate2:
msgbox, template2
return

choosetemplate3:
msgbox, template3
return
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Problem Clearing Hotkeys with GUI  Topic is solved

12 Jun 2019, 11:13

try this

Code: Select all

TemplatePreset1=^1
TemplatePreset2=^2
TemplatePreset3=^3

gui, add, Hotkey, x25 y25 w350 vTemplatePreset1, ^1
gui, add, Hotkey, y+10 w350 vTemplatePreset2, ^2
gui, add, Hotkey, y+10 w350 vTemplatePreset3, ^3
gui,add, button, ,hello

Gui, Show, w500 h500
gosub, refreshhotkeys
return

GuiClose:
ExitApp

refreshhotkeys:
gui, submit, nohide
Hotkey,%TemplatePreset1%,ChooseTemplate1, On UseErrorLevel
Hotkey,%TemplatePreset2%,ChooseTemplate2, On UseErrorLevel
Hotkey,%TemplatePreset3%,ChooseTemplate3, On UseErrorLevel
return

^f::
gui, submit, nohide
Hotkey, %TemplatePreset1%, Off, UseErrorLevel
TemplatePreset1=^4
guicontrol,, TemplatePreset1, ^4
gosub, refreshhotkeys
return

^g::
gui, submit, nohide
Hotkey, %TemplatePreset1%, Off, UseErrorLevel
TemplatePreset1=
guicontrol,, TemplatePreset1,
gosub, refreshhotkeys
return


choosetemplate1:
msgbox, template1
return

choosetemplate2:
msgbox, template2
return

choosetemplate3:
msgbox, template3
return
:wave: There is always more than one way to solve a problem. ;)
doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Re: Problem Clearing Hotkeys with GUI

12 Jun 2019, 12:31

works great, thank you so much. How did you find this option? didnt see it in the help file
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Problem Clearing Hotkeys with GUI

12 Jun 2019, 12:32

:wave: There is always more than one way to solve a problem. ;)
doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Re: Problem Clearing Hotkeys with GUI

12 Jun 2019, 12:40

yup right there, i was blind to it! lesson learned

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 181 guests