Help with ListBox multi

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
CarPiotr
Posts: 40
Joined: 11 Dec 2019, 08:21

Help with ListBox multi

Post by CarPiotr » 03 Dec 2021, 06:51

Hi !
I can't figure it out myself, so please help me.
In LisBox, I select a few fields and after pressing the OK button, MsgBox will appear with info about what fields have been selected.
I need the results to be in separate MsgBox.
Is it possible to set a limit on the number of selected fields? e.g. 5 and if not, could only 5 MsgBox appear and other selections will be ignored. thanks for any help

Code: Select all

List=White|Yellow|Orange|Red|Green|Blue|Violet|Black

Gui, Add, ListBox, Multi vMyListBox r10, %List%
Gui, Add, Button, Default, OK
Gui Show,
Return

ButtonOK:
    Gui, Submit, Nohide
    MsgBox % MyListBox
return

ESC::ExitApp

User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Help with ListBox multi

Post by jNizM » 03 Dec 2021, 07:26

Code: Select all

List=White|Yellow|Orange|Red|Green|Blue|Violet|Black

Gui, Add, ListBox, Multi vMyListBox r10, %List%
Gui, Add, Button, Default, OK
Gui Show,
Return

ButtonOK:
	Gui, Submit, Nohide
	Loop, Parse, MyListBox, |
	{
		if (A_Index > 5)
			return
		MsgBox Selection number %A_Index% is %A_LoopField%.
	}
return

ESC::ExitApp
https://www.autohotkey.com/docs/commands/GuiControls.htm#ListBox_Options -> Multi
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile

User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: Help with ListBox multi

Post by mikeyww » 03 Dec 2021, 07:44

Another one:

Code: Select all

List = White|Yellow|Orange|Red|Green|Blue|Violet|Black
Gui, Font, s10
Gui, Add, ListBox, r8 Multi vbox gCheck, %List%
Gui, Add, Button, Default, OK
Gui, Show,, List
Return

Check:
Gui, Submit, NoHide
RegExReplace(box, "\|",, count)
If (count >= max := 5) {
 PostMessage, 0x0185, 0, -1, ListBox1 ; Deselect all items.
 For each, item in StrSplit(box, "|")
  If Instr("|" last "|", "|" item "|") {
   Sleep, 15
   GuiControl, ChooseString, box, %item%
  }
} Else last := box
Return

ButtonOK:
Gui, Submit, NoHide
For each, item in StrSplit(box, "|")
 MsgBox, 0, Item #%each%, %item%
Return

CarPiotr
Posts: 40
Joined: 11 Dec 2019, 08:21

Re: Help with ListBox multi

Post by CarPiotr » 03 Dec 2021, 15:23

:) thank you guys but i can't say goodbye :roll:

CarPiotr
Posts: 40
Joined: 11 Dec 2019, 08:21

Re: Help with ListBox multi

Post by CarPiotr » 06 Dec 2021, 08:41

Hello !
However, I started it wrong. I gave a simple example and I thought I could do it. Here is part of my test script. I use it for putty connections to different servers. I would like to run a maximum of five simultaneously at intervals or when the previous one connects so that it doesn't interfere with each other. I don't know why I can't send the last command via ControlSend or ControlSendRaw. The server reads it wrong and I have to send a command after activating the window. Please help

Code: Select all

List = White|Yellow|Orange|Red|Green|Blue|Violet|Black
Gui, Font, s10
Gui, Add, ListBox, r8 vList gList, %List%
Gui, Add, Button, gButtonABC, ButtonABC
Gui, Show,, List
Return

GuiEscape:
GuiClose:
ExitApp

List:
if A_GuiEvent = DoubleClick
goto, ButtonABC
Return

ButtonABC:

Gui, Submit, NoHide

RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\ABC\, WinTitle, % ["SERVER 1", "SERVER 2", "SERVER 3", "SERVER 4", "SERVER 5", "SERVER 6", "SERVER 7", "SERVER 8"][List]
Sleep, 100
run C:\Program Files\Putty\putty.exe -load ABC ,,min,PID
IfWinExist, ahk_pid %PID%
WinWait, ahk_pid %PID%
Sleep, 1000
ControlSend,,{Enter},ahk_pid %PID%
ControlSend,,{t},ahk_pid %PID%
ControlSend,,{Enter},ahk_pid %PID%
Sleep, 100
WinActivate, ahk_pid %PID%
SendInput, display-nes:
SendInput, % ["aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh"][List]
SendInput, % "," SubStr(A_ThisLabel, 7) ";"
Return

User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: Help with ListBox multi

Post by mikeyww » 06 Dec 2021, 08:45

Some programs will not return a PID, so check it.

Instead of Run -> IfWinExist, use Run followed by WinWaitActive. Run followed by IfWinExist will usually or often fail because the Run command does not wait for anything. The script immediately proceeds to the next command.

Some windows do not respond to ControlSend. If you are waiting until your window is active, then you can use Send instead of ControlSend anyway.

CarPiotr
Posts: 40
Joined: 11 Dec 2019, 08:21

Re: Help with ListBox multi

Post by CarPiotr » 07 Dec 2021, 03:11

Hi !
This is my last request because I have noticed that my language barriers are also present. I can't use your script for my needs to run up to five putty windows, e.g. every 2 seconds. I know Autohokey from your forum and youtube :-) not knowing English. Thanks

User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: Help with ListBox multi

Post by mikeyww » 07 Dec 2021, 06:11

The following worked here. Window Spy will show you the control names.

Code: Select all

app = d:\utils\putty\putty.exe
Loop, 3 {
 Run, %app%
 Sleep, 500
}
WinGet, putty, List, ahk_exe putty.exe
Loop, %putty%
 ControlSend, Edit1, %A_Index%, % "ahk_id " putty%A_Index%

CarPiotr
Posts: 40
Joined: 11 Dec 2019, 08:21

Re: Help with ListBox multi

Post by CarPiotr » 07 Dec 2021, 06:28

Thank you and best regards !

CarPiotr
Posts: 40
Joined: 11 Dec 2019, 08:21

Re: Help with ListBox multi

Post by CarPiotr » 16 Dec 2021, 08:24

Hi !
Please help with the syntax.
I want to make an entry in the registry so that the window title depends on the choice, for example:

1. Orange

My entry:

RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\BACKUP\, WinTitle, %A_Index%. % ["White", "Yellow", "Orange", "Red", "Green", "Blue", "Violet", "Black"][A_LoopField]

Thanks

User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: Help with ListBox multi

Post by mikeyww » 16 Dec 2021, 11:01

A_LoopField applies only to certain kinds of loops. What is the question, and what is the script? What is the loop? Is "List" your variable (choice)?

CarPiotr
Posts: 40
Joined: 11 Dec 2019, 08:21

Re: Help with ListBox multi

Post by CarPiotr » 16 Dec 2021, 15:28

Hi
test example:

Code: Select all

List= White|Yellow|Orange|Red|Green|Blue|Violet|Black

Gui, Add, ListBox, Multi +AltSubmit gCheck vMyListBox r10, %List%
Gui, Add, Button, Default, OK
Gui Show,
Return

Check:
Gui, Submit, NoHide
RegExReplace(MyListBox, "\|",, count)
If (count >= max := 5) {
 PostMessage, 0x0185, 0, -1, ListBox1
}
Return


ButtonOK:

	Gui, Submit, Nohide
	
Loop, Parse, MyListBox, |
	{
	
	RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\BACKUP\, WinTitle, % ["SERVER 1", "SERVER 2", "SERVER 3", "SERVER 4", "SERVER 5", "SERVER 6", "SERVER 7", "SERVER 8"][A_LoopField]
	Sleep, 300
	run C:\Program Files\Putty\putty.exe -load BACKUP -pw Jesie!234
	
	}
Return

ESC::ExitApp
If I type:

RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\BACKUP\, WinTitle, % ["SERVER 1", "SERVER 2", "SERVER 3", "SERVER 4", "SERVER 5", "SERVER 6", "SERVER 7", "SERVER 8"][A_LoopField]

I get the window title, e.g. SERVER1

If I type:

RegWrite, REG_SZ, HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\BACKUP\, WinTitle, %A_Index%.

I get the window title, e.g. 1.
I want to get: 1. SERVER 1
I can't connect it. Thank you for your understanding

User avatar
mikeyww
Posts: 26882
Joined: 09 Sep 2014, 18:38

Re: Help with ListBox multi

Post by mikeyww » 16 Dec 2021, 15:49

Although one cannot mix literal strings with forced expressions in a single parameter, you can still achieve your goal.

Code: Select all

% A_Index ". " . ["White", "Yellow", "Orange", "Red", "Green", "Blue", "Violet", "Black"][A_LoopField]
Without AltSubmit:

Code: Select all

%A_Index%. %A_LoopField%

CarPiotr
Posts: 40
Joined: 11 Dec 2019, 08:21

Re: Help with ListBox multi

Post by CarPiotr » 17 Dec 2021, 13:58

Thanks for helping me in advance.
Another topic, but I decided to continue here.

I have 6 putty windows and I want to set them to the positions previously saved in the ini file. The windows move but to the left edge of the screen even though the saved positions are correct.
What is wrong ?

Code: Select all

SetTitleMatchMode, 1
	IniRead, backup_position1 , file.ini, backup position, backup_position1
	WinMove, SERVER 1,, %backup_position1%
	IniRead, backup_position2, file.ini, backup position, backup_position2
	WinMove, SERVER 2,, %backup_position2%
	IniRead, backup_position3,file.ini, backup position, backup_position3
	WinMove, SERVER 3,, %backup_position3%
	IniRead, backup_position4, file.ini, backup position, backup_position4
	WinMove, SERVER 4,, %backup_position4%
	IniRead, backup_position5, file.ini, backup position, backup_position5
	WinMove, SERVER 5,, %backup_position5%
	IniRead, backup_position6, file.ini, backup position, backup_position6
	WinMove, SERVER 6,, %backup_position6%
ini file is saved like this:


[backup position]
backup_position1=x1377 y30
backup_position2=x1377 y310
backup_position3=x1377 y584
backup_position4=x870 y32
backup_position5=x870 y310
backup_position6=x870 y584
[window position]
gui_position=x1286 y167

User avatar
KruschenZ
Posts: 45
Joined: 20 Jan 2021, 07:05
Location: Germany (Rheinhessen)
Contact:

Re: Help with ListBox multi

Post by KruschenZ » 17 Dec 2021, 14:18

CarPiotr wrote:
17 Dec 2021, 13:58
Thanks for helping me in advance.
Another topic, but I decided to continue here.

I have 6 putty windows and I want to set them to the positions previously saved in the ini file. The windows move but to the left edge of the screen even though the saved positions are correct.
What is wrong ?

Code: Select all

SetTitleMatchMode, 1
	IniRead, backup_position1 , file.ini, backup position, backup_position1
	WinMove, SERVER 1,, %backup_position1%
	IniRead, backup_position2, file.ini, backup position, backup_position2
	WinMove, SERVER 2,, %backup_position2%
	IniRead, backup_position3,file.ini, backup position, backup_position3
	WinMove, SERVER 3,, %backup_position3%
	IniRead, backup_position4, file.ini, backup position, backup_position4
	WinMove, SERVER 4,, %backup_position4%
	IniRead, backup_position5, file.ini, backup position, backup_position5
	WinMove, SERVER 5,, %backup_position5%
	IniRead, backup_position6, file.ini, backup position, backup_position6
	WinMove, SERVER 6,, %backup_position6%
ini file is saved like this:


[backup position]
backup_position1=x1377 y30
backup_position2=x1377 y310
backup_position3=x1377 y584
backup_position4=x870 y32
backup_position5=x870 y310
backup_position6=x870 y584
[window position]
gui_position=x1286 y167
Hi
for winmove the x and y parameters are separated.
Look there
https://www.autohotkey.com/docs/commands/WinMove.htm

Many regards
KruschenZ

CarPiotr
Posts: 40
Joined: 11 Dec 2019, 08:21

Re: Help with ListBox multi

Post by CarPiotr » 20 Dec 2021, 15:27

Hi !
In my opinion, it should work, but it does not work. What's wrong now?

Code: Select all

	SetTitleMatchMode, 1
	IniRead, backup_position1x , file.ini, backup position, backup_position1x
	IniRead, backup_position1y , file.ini, backup position, backup_position1y
	WinMove, SERVER 1,, %backup_position1x%, %backup_position1y%
	IniRead, backup_position2x , file.ini, backup position, backup_position2x
	IniRead, backup_position2y , file.ini, backup position, backup_position2y
	WinMove, SERVER 2,, %backup_position2x%, %backup_position2y%
	IniRead, backup_position3x , file.ini, backup position, backup_position3x
	IniRead, backup_position3y , file.ini, backup position, backup_position3y
	WinMove, SERVER 3,, %backup_position3x%, %backup_position3y%
	IniRead, backup_position4x , file.ini, backup position, backup_position4x
	IniRead, backup_position4y , file.ini, backup position, backup_position4y
	WinMove, SERVER 4,, %backup_position4x%, %backup_position4y%
	IniRead, backup_position5x , file.ini, backup position, backup_position5x
	IniRead, backup_position5y , file.ini, backup position, backup_position5y
	WinMove, SERVER 5,, %backup_position5x%, %backup_position5y%
	IniRead, backup_position6x , file.ini, backup position, backup_position6x
	IniRead, backup_position6y , file.ini, backup position, backup_position6y
	WinMove, SERVER 6,, %backup_position6x%, %backup_position6y%
The.ini file contains :

[backup position]
backup_position1x=x1390
backup_position1y=y16
backup_position2x=x886
backup_position2y=y17
backup_position3x=x886
backup_position3y=y291
backup_position4x=x885
backup_position4y=y567
backup_position5x=x385
backup_position5y=y18
backup_position6x=x386
backup_position6y=y293

User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Help with ListBox multi

Post by boiler » 20 Dec 2021, 16:12

The values for the X and Y parameters in WinMove are to be just numbers, not preceded by an x or y, so the format of your .ini file entries should be:

Code: Select all

backup_position1x = 1390
backup_position1y = 16

CarPiotr
Posts: 40
Joined: 11 Dec 2019, 08:21

Re: Help with ListBox multi

Post by CarPiotr » 21 Dec 2021, 03:52

Thank you all for your patient help for beginners and those who get lost in their scripts. Happy Christmas . :xmas:

Post Reply

Return to “Ask for Help (v1)”