Page 1 of 1

Sending a variable to a user input box

Posted: 19 Mar 2020, 09:33
by JKnight_xbt33
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

Re: Sending a variable to a user input box  Topic is solved

Posted: 19 Mar 2020, 09:45
by SuperFoobar
Have a look at https://www.autohotkey.com/docs/commands/InputBox.htm

There's a parameter called "Default"

Re: Sending a variable to a user input box

Posted: 20 Mar 2020, 05:16
by JKnight_xbt33
@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}

Re: Sending a variable to a user input box

Posted: 20 Mar 2020, 07:29
by boiler
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

Re: Sending a variable to a user input box

Posted: 25 Mar 2020, 06:23
by JKnight_xbt33
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

Re: Sending a variable to a user input box

Posted: 25 Mar 2020, 08:05
by boiler
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

Re: Sending a variable to a user input box

Posted: 25 Mar 2020, 10:42
by JKnight_xbt33
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

Re: Sending a variable to a user input box

Posted: 25 Mar 2020, 10:49
by boiler
As someone reminded me, you can just use the timeout parameter:

Code: Select all

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