Page 1 of 1

Accept input in an InputBox without Enter?

Posted: 05 Dec 2019, 17:12
by Florian
Hey, I'm new to AHK. I've set up an InputBox that lets me open links that I visit regularly.
The box shows me a list of numbers and their corresponding targets. I type in the number that I want to pick and then confirm it by pressing Ok.
Example:

Code: Select all

^+y::
InputBox, num , Choose a Page, 1: Sub Feed`n2: Playlists`n3: Videos`n4: Creator Studio
if ErrorLevel
return
if num = 1
{
Run "https www.youtube.com /feed/subscriptions"  Broken Link for safety
}
else if num = 2
{
Run "https www.youtube.com /view_all_playlists"  Broken Link for safety
}
else if num = 3 
{
Run "https www.youtube.com /my_videos?o=U&ar=2"  Broken Link for safety
}
else if num = 4
{
Run "https studio.youtube.com /channel/UC_Fh8kvtkVPkeihBs42jGcA"  Broken Link for safety
}
Is there a way to immediately confirm the input without having to press enter first? I just want to press "1" to select the first branch.
Is something else than an InputBox a better choice?

Re: Accept input in an InputBox without Enter?

Posted: 05 Dec 2019, 18:43
by MikeyG12
You may need to use GuiControlGet https://www.autohotkey.com/docs/commands/GuiControlGet.htm in a loop to see if the input box has changed. Let me write something up real quick to see if I can *In Tim Gun's Voice* make it work.

Re: Accept input in an InputBox without Enter?

Posted: 05 Dec 2019, 19:31
by boiler
Using an InputBox isn't the best thing for just wanting to capture a single key press. You could create a GUI, but SplashText is okay for this. Then use Input (not InputBox) to capture the key press. It could be like this:

Code: Select all

^+y::
	SplashTextOn, 300, 130, Choose a Page, 1: Sub Feed`n2: Playlists`n3: Videos`n4: Creator Studio
	Input, num, L1
	SplashTextOff
	if num = 1
		Run "https://www.youtube.com/feed/subscriptions"
	else if num = 2
		Run "https://www.youtube.com/view_all_playlists"
	else if num = 3 
		Run "https://www.youtube.com/my_videos?o=U&ar=2"
	else if num = 4
		Run "https://studio.youtube.com/channel/UC_Fh8kvtkVPkeihBs42jGcA"
return
or if you are using AHK version 1.1.31 or later:

Code: Select all

^+y::
	SplashTextOn, 300, 130, Choose a Page, 1: Sub Feed`n2: Playlists`n3: Videos`n4: Creator Studio
	Input, num, L1
	SplashTextOff
	Switch num
	{
		Case 1:
			Run "https://www.youtube.com/feed/subscriptions"
		Case 2:
			Run "https://www.youtube.com/view_all_playlists"
		Case 3 :
			Run "https://www.youtube.com/my_videos?o=U&ar=2"
		Case 4:
			Run "https://studio.youtube.com/channel/UC_Fh8kvtkVPkeihBs42jGcA"
	}
return

Re: Accept input in an InputBox without Enter?

Posted: 06 Dec 2019, 02:46
by Florian
Yes, exactly what I needed! Thank you guys!

Re: Accept input in an InputBox without Enter?

Posted: 06 Dec 2019, 05:07
by Florian
One more question: Could this be combined with an input box? I want to make a search box where I type in a search term and then press 1 to search for this term on Google, 2 to search on Youtube etc.

Re: Accept input in an InputBox without Enter?

Posted: 06 Dec 2019, 05:28
by boiler
Sure. Just put your InputBox before the SplashText line, so first you’ll enter the search term, then it will bring up the SplashText asking you which search engine to use.

Re: Accept input in an InputBox without Enter?

Posted: 06 Dec 2019, 05:54
by Florian
Makes sense, thank you very much!