Need help with a Gui

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
WarzaSchwii
Posts: 16
Joined: 19 Oct 2021, 14:26

Need help with a Gui

19 Oct 2021, 14:43

Hello, I want to write a script to select a song and then execute a command after selecting it. But i am missing a few things..

- A search option, so when i search for a song, or artist it jumps to it without scrolling for hours (format will be 'Artist - Song')
- A scrollwheel, since i want to include for more than 100 options
- The Part with the song - command communication. So when i for example select song A it should write in the command Song1 instead of A
- When i press the X on the gui or esc it should not close the app, instead return to the beginning, so when i press CTRL+, again, the gui pops up again (I already tried return, GoTo and break without any luck)

Code: Select all


The splashtext part is only in for testing and will later be removed.
Please don't judge my code, since this is one of my first scripts and is mostly from other sources  :roll: 




loop
{

Songs:=
(
"
||
A|
B|
C
"
)


CMD_Song := x


^,::
sleep, 200
	{
		#SingleInstance, Force
		
		Gui, New
		
		Gui, Color, White
		Gui, Margin, +20, +20
		
		Gui, Add, DropdownList, xm ym w200 r100 sort vDDL gSubmit,% Songs
		
		Gui, Add, Button, xm w200 h30 gDo_Something,Confirm!
		
		Gui, Show, ,PlaySound
		return
		
		GuiClose:
			ExitApp
			
		Submit:
			Gui, Submit, NoHide
			return
			
		Do_Something:
			Gui, Submit,
			CMD_Song = %DDL%
			
			SplashTextOn ,110,, Song: %CMD_Song%
			sleep, 1000
			SplashTextOff
			
			break
			
		esc::ExitApp
	}
return
}
User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: Need help with a Gui

19 Oct 2021, 20:25

If you need a GUI for this, then a :arrow: ListView may be a convenient choice, considering your needs.

You can set a hotkey to show your GUI. If you remove your GuiClose subroutine, then pressing the "X" will simply hide the GUI by default.

Some coders get confused about how to show the GUI and believe that they need a loop for some reason. This is typically incorrect. If you look at examples of GUI scripts here on the forum, you can understand how the flow works.

Your hotkey does not need to continue to build a new GUI repeatedly (in most circumstances). You can build the GUI once, and then use a hotkey to show the GUI that has already been built.

I think of common GUI flow in discrete and distinct steps, as follows.

1. Build the GUI.
2. Show the GUI.
3. Submit the GUI.

There is no loop here, though any of these steps can be repeated at any point. A hotkey can be defined to do #2. A GUI button or other control can be defined to do #3.

You seem to use line spacing, indentation, and braces somewhat randomly in your script. In particular, I would examine your use of braces, to eliminate extraneous ones. In some cases, unnecessary braces can actually define bugs that yield unintended effects.

Aside from the Hotkey command, hotkeys are not defined inside loops.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: aitaixy, Anput, Nerafius, RandomBoy and 189 guests