Advertisement
ZxkH

Iteration #13

Feb 7th, 2024
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 9.54 KB | None | 0 0
  1. #include <MsgBoxConstants.au3>
  2. #include <WinAPIFiles.au3>
  3.  
  4. HotKeySet("{F1}", "Start")
  5. HotKeySet("{F2}", "Stop")
  6.  
  7. Global $hAutoclickerWindow = WinGetHandle("[CLASS:AsdaGlobal]")
  8.  
  9. While 1
  10.     Sleep(100)
  11. WEnd
  12.  
  13. Func Start()
  14.     While 1
  15.         If Not WinExists($hAutoclickerWindow) Then
  16.             MsgBox($MB_SYSTEMMODAL, "Error", "AsdaGlobal window not found!")
  17.             Exit
  18.         EndIf
  19.  
  20.         ; Click somewhere in the AsdaGlobal window
  21.         MouseClick("left", 100, 100, 1, 0)
  22.  
  23.         Sleep(1000)
  24.     WEnd
  25. EndFunc   ;==>Start
  26.  
  27. Func Stop()
  28.     Exit
  29. EndFunc   ;==>Stop
  30.  
  31. ;The rest of the code from the pastebin link
  32. Func _FileWriteLog($sMessage, $sFile)
  33.     Local $hFileOpen = FileOpen($sFile, 1)
  34.     If $hFileOpen = -1 Then
  35.         FileWrite($sFile, $sMessage & @CRLF)
  36.     Else
  37.         FileWriteLine($hFileOpen, $sMessage)
  38.         FileClose($hFileOpen)
  39.     EndIf
  40. EndFunc
  41.  
  42. Func _WaitForImage($sImagePath, $iTimeout = 30000)
  43.     Local $iTimerStart = TimerInit()
  44.     While TimerDiff($iTimerStart) < $iTimeout
  45.         If FileExists($sImagePath) Then Return True
  46.         Sleep(100)
  47.     WEnd
  48.     Return False
  49. EndFunc
  50.  
  51. Func _ClickImage($sImagePath)
  52.     Local $aSearch = _ImageSearch($sImagePath, 0, 0, 0, 0)
  53.     If $aSearch[0] = 0 Then Return False
  54.     MouseMove($aSearch[1], $aSearch[2], 10)
  55.     MouseClick("left", $aSearch[1], $aSearch[2], 1, 0)
  56.     Return True
  57. EndFunc
  58.  
  59. Func _ImageSearch($sImagePath, $iLeft, $iTop, $iRight, $iBottom, $iFuzziness = 0)
  60.     Local $aResult = ControlGetHandle("AsdaGlobal", "", 0)
  61.     If $aResult[0] = 0 Then Return SetError(1, 0, 0)
  62.     Local $aSearch = _ImageSearchArea($sImagePath, $iLeft, $iTop, $iRight, $iBottom, $iFuzziness, $aResult[1])
  63.     Return $aSearch
  64. EndFunc
  65.  
  66. Func _ImageSearchArea($sImagePath, $iLeft, $iTop, $iRight, $iBottom, $iFuzziness, $hWnd = 0)
  67.     Local $aSearch = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $iLeft, "int", $iTop, "int", $iRight, "int", $iBottom, "wstr", $sImagePath, "int", $iFuzziness, "hwnd", $hWnd)
  68.     If @error Then Return SetError(@error, @extended, "")
  69.     Return $aSearch
  70. EndFunc
  71.  
  72. #include <MsgBoxConstants.au3>
  73.  
  74. Global $autoClickerWindow
  75.  
  76. ; Open the AutoClicker
  77. $autoClickerWindow = WinGetHandle("[CLASS:AutoClicker]")
  78. If @error Then
  79.     MsgBox($MB_OK, "Error", "AutoClicker window not found.")
  80.     Exit
  81. EndIf
  82.  
  83. Func Example()
  84.     ; This function clicks the button Start on the AutoClicker window
  85.     ControlClick($autoClickerWindow, "", "[CLASS:Button; TEXT:Start]")
  86. EndFunc
  87.  
  88. Func main()
  89.     ; Example of using the $autoClickerWindow handle:
  90.     ; ControlClick($autoClickerWindow, "", "[CLASS:Button; TEXT:Start]")
  91.  
  92.     ; Your main code goes here...
  93. EndFunc
  94.  
  95. #include <GUIConstantsEx.au3>
  96.  
  97. Global $mainWindow, $optionCheckbox[8], $isRunning = False, $monitoringActive = False, $autoClickerActive = False
  98. Global $autoClickerDelay = 1000 ; Default delay for autoclicker (milliseconds)
  99. Global Const $monitoringAreaLeft = 520, $monitoringAreaTop = 460, $monitoringAreaRight = 760, $monitoringAreaBottom = 500
  100.  
  101. <link>$mainWindow</link> = GUICreate("AutoIt Automation", 300, 330)
  102.  
  103. <link>$optionCheckbox[0]</link> = GUICtrlCreateCheckbox("Clicking", 10, 10, 100, 20)
  104. <link>$optionCheckbox[1]</link> = GUICtrlCreateCheckbox("Skills", 10, 40, 100, 20)
  105. <link>$optionCheckbox[2]</link> = GUICtrlCreateCheckbox("Auto Heal", 10, 70, 100, 20)
  106. <link>$optionCheckbox[3]</link> = GUICtrlCreateCheckbox("Target Closest", 10, 100, 120, 20)
  107. <link>$optionCheckbox[4]</link> = GUICtrlCreateCheckbox("Pickup Items", 10, 130, 100, 20)
  108. <link>$optionCheckbox[5]</link> = GUICtrlCreateCheckbox("Digging", 10, 160, 100, 20)
  109. <link>$optionCheckbox[6]</link> = GUICtrlCreateCheckbox("Monitor", 10, 190, 100, 20)
  110. <link>$optionCheckbox[7]</link> = GUICtrlCreateCheckbox("AutoClicker", 10, 220, 100, 20)
  111.  
  112. <link>$btnStartStop</link> = GUICtrlCreateButton("Start/Stop", 10, 270, 100, 30)
  113. <link>$btnExit</link> = GUICtrlCreateButton("Exit", 230, 270, 60, 30)
  114.  
  115. Global $autoClickerWindow, $inpDelay, $btnAutoClickerStartStop, $btnAutoClickerExit
  116.  
  117. <link>$autoClickerWindow</link> = GUICreate("AutoClicker Settings", 200, 120, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_CAPTION))
  118. GUICtrlCreateLabel("Delay (ms):", 10, 10, 100, 20)
  119. <link>$inpDelay</link> = GUICtrlCreateInput("1000", 110, 10, 60, 20)
  120. <link>$btnAutoClickerStartStop</link> = GUICtrlCreateButton("Start", 10, 50, 80, 30)
  121. <link>$btnAutoClickerExit</link> = GUICtrlCreateButton("Exit", 110, 50, 80, 30)
  122. GUISetState(@SW_HIDE, $autoClickerWindow)
  123. <link>$AutoClickerWindow</link> = 0
  124.  
  125. HotKeySet("{End}", "PanicButton") ; Set the "end" key as the panic button
  126.  
  127. GUISetState(@SW_SHOW, $mainWindow)
  128.  
  129. HotKeySet("{End}", "PanicButton") ; Set the "end" key as the panic button
  130.  
  131. GUISetState(@SW_SHOW, $mainWindow)
  132.  
  133. While 1
  134.     $msg = GUIGetMsg()
  135.     Switch $msg
  136.         Case $GUI_EVENT_CLOSE, $btnExit, $btnAutoClickerExit
  137.             Exit
  138.         Case $btnStartStop
  139.             If Not _IsChecked($optionCheckbox) Then
  140.                 MsgBox(48, "Error", "Please select at least one option.")
  141.             Else
  142.                 $isRunning = Not $isRunning
  143.                 If $isRunning Then
  144.                     GUICtrlSetData($btnStartStop, "Stop")
  145.                     StartAutomation()
  146.                 Else
  147.                     MsgBox(64, "Stop", "Stopping automation.")
  148.                     ; Add logic to stop automation tasks
  149.                     GUICtrlSetData($btnStartStop, "Start")
  150.                 EndIf
  151.             EndIf
  152.         Case $optionCheckbox[7] ; Autoclicker checkbox
  153.             If GUICtrlRead($optionCheckbox[7]) = $GUI_CHECKED Then
  154.                 GUISetState(@SW_SHOW, $autoClickerWindow)
  155.             Else
  156.                 GUISetState(@SW_HIDE, $autoClickerWindow)
  157.                 $autoClickerActive = False
  158.             EndIf
  159.         Case $btnAutoClickerStartStop
  160.             If GUICtrlRead($btnAutoClickerStartStop) = "Start" Then
  161.                 GUICtrlSetData($btnAutoClickerStartStop, "Stop")
  162.                 $autoClickerActive = True
  163.                 $autoClickerDelay = GUICtrlRead($inpDelay)
  164.                 StartAutoClicker()
  165.             Else
  166.                 GUICtrlSetData($btnAutoClickerStartStop, "Start")
  167.                 $autoClickerActive = False
  168.             EndIf
  169.     EndSwitch
  170. WEnd
  171.  
  172. Func StartAutomation()
  173.     Local $appWindow, $coords, $result, $tolerance = 10 ; Define tolerance here
  174.  
  175. $appWindow = WinGetHandle("AsdaGlobal")
  176.     If $appWindow = 0 Then
  177.         MsgBox(16, "Error", "Failed to find the target application window.")
  178.         Return
  179.     EndIf
  180.  
  181.     ; Activate the application window
  182.     WinActivate($appWindow)
  183.  
  184.     ; Start monitoring if the monitoring checkbox is checked
  185.     If GUICtrlRead($optionCheckbox[6]) = $GUI_CHECKED Then
  186.         $monitoringActive = True
  187.         StartMonitoring()
  188.     EndIf
  189.  
  190.     While $isRunning
  191.         ; Add your automation logic here
  192.  
  193.         If GUICtrlRead($optionCheckbox[0]) = $GUI_CHECKED Then
  194.             ; Clicking option selected
  195.             $coords = PixelSearch(1110, 642, 360, 110, 0x6A140A, 40)
  196.             If Not @error Then
  197.                 MouseClick("left", $coords[0], $coords[1], 2, 1)
  198.                 Sleep(700)
  199.             EndIf
  200.         EndIf
  201.  
  202.         If GUICtrlRead($optionCheckbox[3]) = $GUI_CHECKED Then
  203.             ; Target Closest option selected
  204.             Send("{TAB 5}") ; Presses the Tab key 5 times.
  205.             Sleep(100)
  206.         EndIf
  207.  
  208.         If GUICtrlRead($optionCheckbox[4]) = $GUI_CHECKED Then
  209.             ; Pickup Items option selected
  210.             For $i = 1 To Random(1, 15) ; Send "2" a random number of times between 1 and 15
  211.                 Send("2")
  212.                 Sleep(Random(100, 300)) ; Add a random sleep after each keypress
  213.             Next
  214.         EndIf
  215.  
  216.         If GUICtrlRead($optionCheckbox[5]) = $GUI_CHECKED Then
  217.             ; Digging option selected
  218.             Send("1")
  219.             Sleep(7000) ; Wait 7 seconds
  220.             Send("2")
  221.             Sleep(200)
  222.             Send("1")
  223.             Sleep(200)
  224.             Send("2")
  225.         EndIf
  226.  
  227.         Sleep(100) ; Add a delay between iterations to prevent excessive CPU usage
  228.     WEnd
  229. EndFunc
  230.  
  231. Func StartMonitoring()
  232.     While $monitoringActive
  233.         ; Check for the appearance of the box with options in the specified area
  234.         If PixelSearchBox($monitoringAreaLeft, $monitoringAreaTop, $monitoringAreaRight, $monitoringAreaBottom) Then
  235.             ; Found the box, double left-click to select the reddish orange option
  236.             MouseClick("left", $coords[0], $coords[1], 2, 0)
  237.             Sleep(100)
  238.             MouseClick("left", $coords[0], $coords[1], 2, 0)
  239.             Sleep(100)
  240.             Send("{ENTER}")
  241.             Sleep(500)
  242.             Send("Sorry I'm busy atm 2 minutes", 35) ; Type the message with a delay of 35ms between each keystroke
  243.             Sleep(100) ; Wait 100ms before pressing enter again
  244.             Send("{ENTER}")
  245.         EndIf
  246.         Sleep(1000)
  247.     WEnd
  248. EndFunc
  249.  
  250. Func PixelSearchBox($left, $top, $right, $bottom)
  251.     ; Adjust the search area to the specified coordinates
  252.     Local $boxCoords = PixelSearch($left, $top, $right, $bottom, 0xFFFFFF, 10)
  253.     If Not @error Then
  254.         ; Found the box, return true
  255.         $coords = $boxCoords
  256.         Return True
  257.     EndIf
  258.     ; Box not found
  259.     Return False
  260. EndFunc
  261.  
  262. Func PanicButton()
  263.     ; Add the logic for the panic button action here
  264.     Exit
  265. EndFunc
  266.  
  267. Func StartAutoClicker()
  268.     While $autoClickerActive
  269.         MouseClick("left") ; Perform a left click
  270.         Sleep($autoClickerDelay) ; Delay between clicks
  271.     WEnd
  272. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement