[HELP!!!] Autoit ListView conundrum

03/10/2013 03:28 tantrim#1
So i've been beating my head against the wall for some hours now and can't figure this out.

Im unsure on how to link a single(1) ListViewItem to a single(1) function. Although i have several functions and list items that I would like to link together. I'm attempting to use a button to do the selection but i'm not much of a programmer.

I would like to link the Anhur() function to the ListItem labeled Anhur. Currently right now, when i run the program, the anhur function is running 100% of the time, but I want it to only work when its ListItem has been selected with the button. I think it could possibly be done with a GUISetOnEvent but am unsure on how to do this.

btw, ive been using alot of different peoples codes trying to complete this as im not a programmer, so if you see anything that could be deleted without hindering functionality feel free to share.

Thanks in Advance to anyone who helps me!!!

Code:
#include <GuiListBox.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>

Global $listview
Opt("GUIOnEventMode", 1)
 
 
_Main()

Func _Main()
	 
  $listGUI = GUICreate("easyScript", 220, 200, 100, 100, -1)
  GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close_Main")
  $listview = GUICtrlCreateListView("Gods", 10, 10, 200, 150)
  _GUICtrlListView_SetColumnWidth($listview, 0, 196)


  GUICtrlCreateListViewItem("Anhur", $listview)
  GUICtrlCreateListViewItem("Freya", $listview)
	
  $selectGod = GUICtrlCreateButton("Select God", 33, 165, 160, 30)
  GUICtrlSetOnEvent(-1, "SelectItem")
  
  GUISetState()
		
EndFunc   ;==>_Main
 
 
Func SelectItem()
  $sItem = GUICtrlRead(GUICtrlRead($listview))
  MsgBox(0, "Selected Item", $sItem)
EndFunc


 
;---------------------------------------
; Anhur
;---------------------------------------
While 1
   HotKeySet("{F1}", "Anhur")
WEnd

   Func Anhur();
	  send("{1}")
		 mouseclick("")
		 Sleep(400)
	  send("{2}")
		 mouseclick("")
		 Sleep(550)
	  send("{4}")
		 mouseclick("")
   EndFunc


Func On_Close_Main()
   Exit
EndFunc
03/10/2013 10:44 lolkop#2
i would highly suggest to use a simple list, since you've got only one cell in your listview...

beside that, if i understood you right, you wanted to to only use the select god function once, when the button gets clicked... since you'll have to wait for the gui to get inactive, to not send and click on the gui only, you'll have to place the logic outside the normal gui events, and use a special state variable to run the actions...

in the end it could look like this:
Code:
Dim $state = 0, $x=0, $t, $anhur[3][2] = [[1,0],[2,450],[4,550]]
$gui = GUICreate("easyScript", 220, 200, Default, Default, 0x10C80000, 8)
$list = GUICtrlCreateList("Anhur", 10, 10, 200, 150)
GUICtrlSetData(-1, "Freya")
$selectGod = GUICtrlCreateButton("Select God", 33, 165, 160, 30)

While True
	Switch GUIGetMsg()
		Case -3
			Exit
		Case $selectGod
			Switch GUICtrlRead($list)
				Case "Anhur"
					$state = 1
				Case "Freya"
					$state = 2
			EndSwitch
		Case Else
			Switch $state
				Case 0
				Case 1
					If Not WinActive($gui) And TimerDiff($t)>=$anhur[$x][1] Then
						Send(&$anhur[$x][0])
						MouseClick("left")
						$t = TimerInit()
						$x += 1
						If $x >= UBound($anhur) Then
							$x = 0
							$state = 0
						EndIf
					EndIf
				Case 2
			EndSwitch
	EndSwitch
WEnd