Repeating Key syntax

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
thegrove
Posts: 11
Joined: 16 Jun 2020, 09:43

Repeating Key syntax

Post by thegrove » 25 May 2021, 04:48

I cannot quite get this to work.

I have a GUI that captures some user input, for example, the number of Right steps. This part all works fine.

Code: Select all

Gui, Add, Edit, x180 y20 w80 h20 vRGT,
Now I want to pass the variable RGT to a Send command thus:

Code: Select all

Send {Right %RGT%}
but that doesn't work.

Do I have to use a Loop instead?

Code: Select all

Loop, %RGT%
   Send {Right} 

gregster
Posts: 9114
Joined: 30 Sep 2013, 06:48

Re: Repeating Key syntax

Post by gregster » 25 May 2021, 05:34

hard to say with the little code shown (although definitely no loop needed), but I guess you didn't submit the GUI variable before using it - then it should work:

Code: Select all

Gui, Submit, NoHide   ; or Gui, Submit 	-- if the GUI should be hidden
; ...
Send {Right %RGT%}
See https://www.autohotkey.com/docs/commands/Gui.htm#Submit

Of course, at the time of sending the keys, the right control element needs to be active, to have an effect. That could be another hurdle.

thegrove
Posts: 11
Joined: 16 Jun 2020, 09:43

Re: Repeating Key syntax

Post by thegrove » 25 May 2021, 09:19

Sorry, I was trying to keep it simple! Here is the full code:

Code: Select all

^t::
Gui, Add, Text, x12 y20 w160 h30, No. of steps right: 
Gui, Add, Edit, x180 y20 w80 h20 vRGT, 
Gui, Add, Button, x200 y120 w40 h30 , OK 
Gui, Show, x345 y288 h200 w327, Capture 
Return

ButtonOK: 
Gui, Submit 
Return

Send {Right %RGT%}}
Return

gregster
Posts: 9114
Joined: 30 Sep 2013, 06:48

Re: Repeating Key syntax

Post by gregster » 25 May 2021, 09:47

Your line Send {Right %RGT%}} is currently unreachable, doesn't get executed. Also, it has one } too much in it (other than your line presented in your original post).

You could remove the return after Gui, Submit, assuming that after closing the GUI, the correct control element or GUI gets active...

Also, especially (but not only) if you want to use the hotkey repeatedly and not only once, you should create the GUI at the top of the script, and reduce the hotkey subroutine code to just Gui, Show....
Otherwise, you'll get an error from second hotkey usage onwards.

thegrove
Posts: 11
Joined: 16 Jun 2020, 09:43

Re: Repeating Key syntax

Post by thegrove » 25 May 2021, 10:52

Perfect, all works as I hoped now:

Code: Select all

Gui, Add, Text, x12 y20 w160 h30, No. of steps right: 
Gui, Add, Edit, x180 y20 w80 h20 vRGT, 
Gui, Add, Button, x200 y120 w40 h30 , OK 

^t::
Gui, Show, x345 y288 h200 w327, Capture 
Return

ButtonOK: 
Gui, Submit 

Send {Right %RGT%}
Return

Thanks.

Post Reply

Return to “Ask for Help (v1)”