Accept input in an InputBox without Enter?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Florian
Posts: 30
Joined: 05 Dec 2019, 09:05

Accept input in an InputBox without Enter?

05 Dec 2019, 17:12

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?
MikeyG12
Posts: 30
Joined: 03 May 2018, 14:21

Re: Accept input in an InputBox without Enter?

05 Dec 2019, 18:43

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.
User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Accept input in an InputBox without Enter?

05 Dec 2019, 19:31

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
Florian
Posts: 30
Joined: 05 Dec 2019, 09:05

Re: Accept input in an InputBox without Enter?

06 Dec 2019, 02:46

Yes, exactly what I needed! Thank you guys!
Florian
Posts: 30
Joined: 05 Dec 2019, 09:05

Re: Accept input in an InputBox without Enter?

06 Dec 2019, 05:07

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.
User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Accept input in an InputBox without Enter?

06 Dec 2019, 05:28

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.
Florian
Posts: 30
Joined: 05 Dec 2019, 09:05

Re: Accept input in an InputBox without Enter?

06 Dec 2019, 05:54

Makes sense, thank you very much!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], haomingchen1998, robodesign and 239 guests