Autoit multiple windows

10/17/2013 15:00 mlukac89#1
Hi
IS it possible to make autoit work with multiple window for example i have 5 windows of running game, now i need when i start bot to ask me what window i want to choose. Please help :)
10/17/2013 15:27 alpines#2
You can click on the window you want to have and then use
Code:
$sWindowTitle = WinGetTitle("[active]")
to get the current Title, so you can work with it.
10/17/2013 15:43 mlukac89#3
i dont know what you mean im new in this can you show me in my code ?

Code:
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>

Global $Paused
Hotkeyset("{F8}","Quit")
Hotkeyset("{F7}","TogglePause")

$hwnd = WinGetHandle("Game")

AutoItSetOption("WinTitleMatchMode", 4)

If ProcessExists("game.exe") Then
    WinActivate($hwnd)
Else
    MsgBox(0, "Error", "Game is not running.")
EndIf

While 1
	Winsetstate($hwnd,"",@SW_MINIMIZE) ; setting window to work minimized
	Sleep(200)
	ControlSend($hwnd,"","","{TAB}")
	Sleep(200)
	ControlSend($hwnd,"","","{3}")
	Sleep(3000)
	ControlSend($hwnd,"","","{4}")
	Sleep(1000)
	ControlSend($hwnd,"","","{4}")
	Sleep(7000)
WEnd

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('BOT PAUSED', 533, 362)
    WEnd
    ToolTip("")
EndFunc  ;==>Toggle pause on/off

Func Quit()
	Exit
EndFunc   ;==>Quits bot
so i started 5 windows and all have the same name, now i dont know how to recognize what window to choose and how :(
10/17/2013 15:45 berkay2578#4
Code:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Lister", 173, 235, 192, 146, BitOr($GUI_SS_DEFAULT_GUI, $WS_CAPTION))
$procLST = GUICtrlCreateList("", 16, 8, 137, 149)
$exeTXT = GUICtrlCreateInput("Process Name (with .exe)", 16, 168, 137, 21)
$lstBTN = GUICtrlCreateButton("List Processes!", 16, 200, 139, 25)
GUISetState(@SW_SHOW)

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $lstBTN
			GUICtrlSetData($procLST, '')
			$proc = ProcessList(GUICtrlRead($exeTXT))
			For $i = 1 To UBound($proc) - 1
				$node = $proc[$i][0] & ' - PID: ' & $proc[$i][1]
				GUICtrlSetData($procLST, $node)
			Next
	EndSwitch
WEnd
this should work in most cases :p
10/17/2013 16:11 butter123#5
titels can be the same for multiple windows i think. use the window handle to identify them.

_ArrayAdd($windows,WinGetHandle(""))
MsgBox(0,"","Added Window " & WinGetTitle(WinGetHandle("")))

adds the handle of the active window to $windows
10/17/2013 16:12 mlukac89#6
Thanks man i love you :) it works to get process list but i modified gui a bit

Code:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 387, 187, 293, 233)
$lstBTN = GUICtrlCreateButton("Detect running windows", 8, 8, 145, 25)
$Button2 = GUICtrlCreateButton("Start bot", 160, 8, 105, 25)
$Button3 = GUICtrlCreateButton("Toggle pause", 272, 8, 105, 25)
$procLST = GUICtrlCreateList("", 8, 40, 145, 136)
;$exeTXT = GUICtrlCreateInput("game.exe", 16, 168, 137, 21)
GUISetState(@SW_SHOW)


While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $lstBTN
			GUICtrlSetData($procLST, '')
			$proc = ProcessList("game.exe")
			For $i = 1 To UBound($proc) - 1
				$node = $proc[$i][0] & ' - PID: ' & $proc[$i][1]
				GUICtrlSetData($procLST, $node)
			Next
	EndSwitch
WEnd
Now can you help when i click "Detect running windows" i get list, now how to make it when i chose window i want to start and press start button to get focus on chosen window and activate it ? My last wish :)
10/17/2013 16:46 berkay2578#7
GUI was just an example :p

Code:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#include <Array.au3>

$Form1 = GUICreate("Lister", 173, 235, 192, 146, BitOr($GUI_SS_DEFAULT_GUI, $WS_CAPTION))
$procLST = GUICtrlCreateList("", 16, 8, 137, 149)
$exeTXT = GUICtrlCreateInput("Process Name (with .exe)", 16, 168, 137, 21)
$lstBTN = GUICtrlCreateButton("List Processes!", 16, 200, 139, 25)
GUISetState(@SW_SHOW)

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $lstBTN
			GUICtrlSetData($procLST, '')
			$proc = ProcessList(GUICtrlRead($exeTXT))
			For $i = 1 To UBound($proc) - 1
				$node = $proc[$i][0] & ' - PID: ' & $proc[$i][1]
				GUICtrlSetData($procLST, $node)
			Next
		Case $procLST ; when you click the listbox, this event will fire
			If (GUICtrlRead($procLST) <> "") Then
				Local $pid = _StringBetween(GUICtrlRead($procLST), "PID: ", "")
				Local $titleLST = WinList()
				For $i = 1 To $titleLST[0][0]
					If $titleLST[$i][0] <> "" And WinGetProcess($titleLST[$i][1]) = $pid[0] Then
						WinActivate($titleLST[$i][1])
						ExitLoop
					EndIf
				Next
			EndIf
	EndSwitch
WEnd
10/17/2013 16:55 mlukac89#8
Thanks very much <3 :)
10/17/2013 17:05 berkay2578#9
Quote:
Originally Posted by mlukac89 View Post
Thanks very much <3 :)
It was my pleasure :p