Sending a variable to a user input box Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
JKnight_xbt33
Posts: 88
Joined: 18 Sep 2019, 02:06

Sending a variable to a user input box

19 Mar 2020, 09:33

Dear all,
I searched the threads but this has alluded me.

I am trying to send the variable %complaint% to the 2nd user input box that appears in my script. Avoiding the need to manually type it.

The user input box uses control class Edit1. Is there a correct way to send variables to input boxes?

Using ControlSetText,Edit1, %complaint% didn't work as expected

Code: Select all

^#t::

setkeydelay , -1
WinGet,ID,ID,A
InputBox, complaint, Enter complaint ;1st INPUT BOX
WinActivate,ahk_id %ID%
send ^+{s}  ;shortcut for file-> save as
WinWaitActive, Save As ; WainWait executes the next command immediately after the window appear which can case problems
sleep, 1000
ControlSetText,Edit1, %complaint% initial assessment,A
sleep, 100	
InputBox, folder, Enter folder ; 2nd INPUT BOX
sleep, 1000
ControlSetText,Edit1, %complaint% 
sleep, 100
send {Enter}
Once again appreciate your help. You guys are absolute geniuses.

J
JKnight_xbt33
Posts: 88
Joined: 18 Sep 2019, 02:06

Re: Sending a variable to a user input box

20 Mar 2020, 05:16

@SuperFoobar thanks your suggestion worked correctly!

See below changed script.

Code: Select all

InputBox, folder, Enter folder,,,,,,,,, %complaint%

Question:
Is there a way to automatically press ok on the input box without having to manually press enter? If i add a sleep and send enter this doesn't work.See below my attempt.

Code: Select all

InputBox, folder, Enter folder,,,,,,,,, %complaint%
sleep, 3000
send {Enter}
User avatar
boiler
Posts: 5299
Joined: 21 Dec 2014, 02:44

Re: Sending a variable to a user input box

20 Mar 2020, 07:29

JKnight_xbt33 wrote:
20 Mar 2020, 05:16
Question: Is there a way to automatically press ok on the input box without having to manually press enter?
You can do it like this:

Code: Select all

SetTimer, SendEnter, -3000
InputBox, folder, Enter folder,,,,,,,,, %complaint%
return

SendEnter:
Send {Enter}
return
JKnight_xbt33
Posts: 88
Joined: 18 Sep 2019, 02:06

Re: Sending a variable to a user input box

25 Mar 2020, 06:23

Hi @boiler ,

I tried using the first part of your code on its own

error: Target label does not exist

Code: Select all

SetTimer, SendEnter, -3000
InputBox, folder, Enter folder,,,,,,,,, %complaint%
return
However after adding the sendEnter: part of your code as below then it worked somewhat but run into an issue.

Code: Select all

SetTimer, SendEnter, -3000
InputBox, folder, Enter folder,,,,,,,,, %complaint%
SendEnter:
problem: input box doesn't close down like normal like if I would have manually clicked ok. It needs to close to allow the next part of my script to function

Am I understanding the usage correctly?

Thanks
J
User avatar
boiler
Posts: 5299
Joined: 21 Dec 2014, 02:44

Re: Sending a variable to a user input box

25 Mar 2020, 08:05

You never put ALL the code in. You can’t just decide to leave some of the lines out and expect it to work. Put in the lines that appear after the SendEnter label as well:

Code: Select all

SetTimer, SendEnter, -3000
InputBox, folder, Enter folder,,,,,,,,, %complaint%
return

SendEnter:
Send {Enter}
return
JKnight_xbt33
Posts: 88
Joined: 18 Sep 2019, 02:06

Re: Sending a variable to a user input box

25 Mar 2020, 10:42

I understand now. This is the first time I had seen 2 returns in the same block of code so didnt know what to make of it.

The code is working perfectly and here it is (time reduced) for anyone who may find this useful

Code: Select all

setkeydelay , -1
WinGet,ID,ID,A
InputBox, complaint, Enter complaint
WinActivate,ahk_id %ID%
send ^+{s}  ;shortcut for file-> save as
WinWaitActive, Save As ; WainWait executes the next command immediately after the window appear which can case problems
sleep, 1000
ControlSetText,Edit1, %complaint% initial assessment,A
sleep, 100	
SetTimer, SendEnter, -1000
InputBox, folder, Enter folder,,,,,,,,, %complaint%
return

SendEnter:
Send {Enter}

sleep, 500
;rest of my script (private confidential folders)
 return
Thank you for your help,
very much appreciated
J
User avatar
boiler
Posts: 5299
Joined: 21 Dec 2014, 02:44

Re: Sending a variable to a user input box

25 Mar 2020, 10:49

As someone reminded me, you can just use the timeout parameter:

Code: Select all

 InputBox, folder, Enter folder,,,,,,,, 3, %complaint%

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Cyano, gen3egale, Google [Bot], MrDoge, Splongus, tee_rock and 72 guests