Jump to content

Petrask24

Members
  • Posts

    15
  • Joined

  • Last visited

Everything posted by Petrask24

  1. I've decided to give up on this issue. Could a moderator delete this thread? Thanks!
  2. For anyone that may be interested, this is the solution I ended up settling with. #include <authread.au3> #include <ImageSearch2015.au3> Global $Image1 = "Image1.PNG" Global $Image2 = "Image2.PNG" Global $x1 = 0 Global $y1 = 0 Global $WindowX = 500 Global $WindowY = 500 Global $WindowXX = 1000 Global $WindowYY = 1000 Global $Timeout = 5000 Global $Window_Name = "untitled - Notepad" Global $Message = "" test3() Func Test3() _AuThread_Startup() WinActivate($Window_Name) $thread1 = _AuThread_StartThread("thread1") $thread2 = _AuThread_StartThread("thread2") $Timer = TimerInit() do $Message = _AuThread_GetMessage() until $Message or TimerDiff($Timer) >= 5000 ConsoleWrite($Message & @CRLF) EndFunc Func thread1() $Window = WinGetPos($Window_Name) $Timer = TimerInit() do $result = _ImageSearchArea($Image1, 1, $Window[0] + $WindowX, $Window[1] + $WindowY, $Window[0] + $WindowXX, $Window[1] + $WindowYY, $x1, $y1, 0, 0) until $result = 1 or TimerDiff($Timer) >= $Timeout If ($result) Then _AuThread_SendMessage(_AuThread_MainThread(), 1) EndIf EndFunc Func thread2() $Window = WinGetPos($Window_Name) $Timer = TimerInit() do $result = _ImageSearchArea($Image2, 1, $Window[0] + $WindowX, $Window[1] + $WindowY, $Window[0] + $WindowXX, $Window[1] + $WindowYY, $x1, $y1, 0, 0) until $result = 1 or TimerDiff($Timer) >= $Timeout If ($result) Then _AuThread_SendMessage(_AuThread_MainThread(), 2) EndIf EndFunc
  3. Thanks for merging that for me, @Jos. I'll try to further explain my script and the issue I'm having. Please note that I've modified this script from past posts. The variable $slots will be used in future code. The idea is to have the image searches happen continuously until they either return true or timeout. I found this in some documentation online that could be helpful: int _AuThread_StartThread(string $sCallback [, string $sMsg ] ) Could I somehow use this callback to get the first variable to return (and possibly end all other processes)? #include <authread.au3> #include <ImageSearch2015.au3> Global $slots = -1 _AuThread_Startup() _GetAvailableSlots() Func _GetAvailableSlots() $thread1 = _AuThread_StartThread("thread1") $thread2 = _AuThread_StartThread("thread2") $thread3 = _AuThread_StartThread("thread3") $thread4 = _AuThread_StartThread("thread4") EndFunc Func thread1() Local $x1 = 0, $y1 = 0, $WindowX = 0, $WindowY = 0, $WindowXX = 1200, $WindowYY = 900, $Timeout = 5000 Local $Image1 = "Images/Image1.PNG", $Image2 = "Images/Image2.PNG" Local $Image3 = "Images/Image3.PNG", $Image3 = "Images/Image4.PNG" $Timer = TimerInit() do $result = _ImageSearchArea($Image1, 1, $WindowX, $WindowY, $WindowXX, $WindowYY, $x1, $y1, 0, 0) until $result or TimerDiff($Timer) >= $Timeout If ($result) Then $slots = 1 ;This does not work since it is a "separate process" ;Add code here to return the value of 1 for $slots EndIf EndFunc Func thread2() Local $x1 = 0, $y1 = 0, $WindowX = 0, $WindowY = 0, $WindowXX = 1200, $WindowYY = 900, $Timeout = 5000 Local $Image1 = "Images/Image1.PNG", $Image2 = "Images/Image2.PNG" Local $Image3 = "Images/Image3.PNG", $Image3 = "Images/Image4.PNG" $Timer = TimerInit() do $result = _ImageSearchArea($Image1, 1, $WindowX, $WindowY, $WindowXX, $WindowYY, $x1, $y1, 0, 0) until $result or TimerDiff($Timer) >= $Timeout If ($result) Then $slots = 2 ;This does not work since it is a "separate process" ;Add code here to return the value of 2 for $slots EndIf EndFunc Func thread3() Local $x1 = 0, $y1 = 0, $WindowX = 0, $WindowY = 0, $WindowXX = 1200, $WindowYY = 900, $Timeout = 5000 Local $Image1 = "Images/Image1.PNG", $Image2 = "Images/Image2.PNG" Local $Image3 = "Images/Image3.PNG", $Image3 = "Images/Image4.PNG" $Timer = TimerInit() do $result = _ImageSearchArea($Image1, 1, $WindowX, $WindowY, $WindowXX, $WindowYY, $x1, $y1, 0, 0) until $result or TimerDiff($Timer) >= $Timeout If ($result) Then $slots = 3 ;This does not work since it is a "separate process" ;Add code here to return the value of 3 for $slots EndIf EndFunc Func thread4() Local $x1 = 0, $y1 = 0, $WindowX = 0, $WindowY = 0, $WindowXX = 1200, $WindowYY = 900, $Timeout = 5000 Local $Image1 = "Images/Image1.PNG", $Image2 = "Images/Image2.PNG" Local $Image3 = "Images/Image3.PNG", $Image3 = "Images/Image4.PNG" $Timer = TimerInit() do $result = _ImageSearchArea($Image1, 1, $WindowX, $WindowY, $WindowXX, $WindowYY, $x1, $y1, 0, 0) until $result or TimerDiff($Timer) >= $Timeout If ($result) Then $slots = 4 ;This does not work since it is a "separate process" ;Add code here to return the value of 4 for $slots EndIf EndFunc Thanks in advance, I appreciate you taking the time.
  4. My apologies, I didn't think posting two things about two different topics would be so overkill. To be honest, I sort of gave up on the other issue with hope of coming back to it in a day or two. In the meantime, I found a fix that will work for now. Now I'm onto this issue, which I again can't proceed unless I settle for a less than adequate solution.
  5. Here is another post that could be helpful. Same issue but with MouseClick. I've read through the comments and can't find a solution, hoping someone else can determine the issue I'm having at this point.
  6. I am currently trying to use _MouseClickPlus on a window that does not use any controls, therefore I am having a hard time using the function to click. I have tried several different versions of code, all listed below. Original based off of hendrikhe #include <Array.au3> AutoItSetOption("MouseCoordMode", 0) ;=============================================================================== ; ; Function Name: _MouseClickPlus() ; Version added: 0.1 ; Description: Sends a click to window, not entirely accurate, but works ; minimized. ; Parameter(s): $Window = Title of the window to send click to ; $Button = "left" or "right" mouse button ; $X = X coordinate ; $Y = Y coordinate ; $Clicks = Number of clicks to send ; Remarks: You MUST be in "MouseCoordMode" 0 to use this without bugs. ; Author(s): Insolence <insolence_9@yahoo.com> ; ;=============================================================================== Main() Func Main() $Window = "My Window" ;Changed for privacy $ControlID = WinGetHandle($Window,"") _MouseClickPlus($ControlID, "right", 0, 0, 1) EndFunc Func _MouseClickPlus($Window, $Button = "left", $X = "", $Y = "", $Clicks = 1) Local $MK_LBUTTON = 0x0001 Local $WM_LBUTTONDOWN = 0x0201 Local $WM_LBUTTONUP = 0x0202 Local $MK_RBUTTON = 0x0002 Local $WM_RBUTTONDOWN = 0x0204 Local $WM_RBUTTONUP = 0x0205 Local $WM_MOUSEMOVE = 0x0200 Local $i = 0 Select Case $Button = "left" $Button = $MK_LBUTTON $ButtonDown = $WM_LBUTTONDOWN $ButtonUp = $WM_LBUTTONUP Case $Button = "right" $Button = $MK_RBUTTON $ButtonDown = $WM_RBUTTONDOWN $ButtonUp = $WM_RBUTTONUP EndSelect If $X = "" OR $Y = "" Then $MouseCoord = MouseGetPos() $X = $MouseCoord[0] $Y = $MouseCoord[1] EndIf For $i = 1 to $Clicks DllCall("user32.dll", "int", "SendMessage", _ "hwnd", WinGetHandle( $Window ), _ "int", $WM_MOUSEMOVE, _ "int", 0, _ "long", _MakeLong($X, $Y)) DllCall("user32.dll", "int", "SendMessage", _ "hwnd", WinGetHandle( $Window ), _ "int", $ButtonDown, _ "int", $Button, _ "long", _MakeLong($X, $Y)) DllCall("user32.dll", "int", "SendMessage", _ "hwnd", WinGetHandle( $Window ), _ "int", $ButtonUp, _ "int", $Button, _ "long", _MakeLong($X, $Y)) Next EndFunc Func _MakeLong($LoWord,$HiWord) Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF)) EndFunc A recent version by Nine #include <Constants.au3> #include <WinAPISysWin.au3> #include <WinAPIError.au3> #include <WinAPIConv.au3> _Main () Func _Main () Local $ctrl_handle $Window = "My Window" ;Changed for privacy Local $hWnd = WinGetHandle($Window,"") Local $tPoint = DllStructCreate($tagPOINT) DllStructSetData($tPoint, "X", 500) DllStructSetData($tPoint, "Y", 500) _WinAPI_ScreenToClient ($hWnd, $tPoint) MsgBox (0,"Test",DllStructgetData($tPoint, "X") & "/" & DllStructGetData($tPoint, "Y")) Local $thWnd = $hWnd While True $ctrl_handle = _WinAPI_ChildWindowFromPointEx ($hWnd, $tPOINT) if not $ctrl_handle then MsgBox (0,"Error","Failure in finding the child window") Exit endif if $ctrl_handle = $thWnd then ExitLoop $thWnd = $ctrl_handle Wend MsgBox (0,"Handle", $thWnd) _MouseClickPlus($thWnd, "left", DllStructgetData($tPoint, "X"), DllStructGetData($tPoint, "Y"), 1) $tPoint = 0 EndFunc Func _MouseClickPlus($hWnd, $sButton = 'left', $vX = '', $vY = '', $iClicks = 1) Local $MK_LBUTTON = 0x0001 Local $WM_LBUTTONDOWN = 0x0201 Local $WM_LBUTTONUP = 0x0202 Local $MK_RBUTTON = 0x0002 Local $WM_RBUTTONDOWN = 0x0204 Local $WM_RBUTTONUP = 0x0205 Local $WM_MOUSEMOVE = 0x0200 If $sButton = 'left' Then $Button = $MK_LBUTTON $ButtonDown = $WM_LBUTTONDOWN $ButtonUp = $WM_LBUTTONUP ElseIf $sButton = 'right' Then $Button = $MK_RBUTTON $ButtonDown = $WM_RBUTTONDOWN $ButtonUp = $WM_RBUTTONUP EndIf If $vX = "" Or $vY = "" Then $MouseCoord = MouseGetPos() $vX = $MouseCoord[0] $vY = $MouseCoord[1] EndIf Local $stPoint = _MakeLong($vX, $vY) Local $i = 0 For $i = 1 To $iClicks _PostMessage($hWnd, $WM_MOUSEMOVE, 0, $stPoint) _PostMessage($hWnd, $ButtonDown, $Button, $stPoint) _PostMessage($hWnd, $ButtonUp, $Button, $stPoint) Next EndFunc Func _MakeLong($LoWord,$HiWord) Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF)) EndFunc Func _PostMessage($hWnd, $iMsg, $iwParam, $ilParam) Local $aResult, $err $aResult = DllCall("User32.dll", "bool", "PostMessageA", "hwnd", $hWnd, "int", $iMsg, "int", $iwParam, "int", $ilParam) $err = _WinAPI_GetLastError () if $err or not $aResult[0] then MsgBox (0,"Error","Access denied in post message with error " & $err) Exit endif Return $aResult[0] EndFunc Any help/suggestions on this would be greatly appreciated!
  7. Removed
  8. Honestly, all I need it to return is true or false.
  9. I'll be doing an image search in each of them, which as I have it set up could take a bit of time. #include <authread.au3> _AuThread_Startup() Func _GetAvailableSlots() Global $slots = -1 $thread1 = _AuThread_StartThread("thread1") $thread2 = _AuThread_StartThread("thread2") $thread3 = _AuThread_StartThread("thread3") $thread4 = _AuThread_StartThread("thread4") ConsoleWrite($slots & @CRLF) EndFunc Func thread1() Local $x1 = 0, $y1 = 0 $result = _ImageSearchArea($Image, 1, $WindowX, $WindowY, $WindowX, $WindowY, $x1, $y1, 0, 0) If ($result) Then $slots = 1 EndIf EndFunc Func thread2() Local $x1 = 0, $y1 = 0 $result = _ImageSearchArea($Image, 1, $WindowX, $WindowY, $WindowX, $WindowY, $x1, $y1, 0, 0) If ($result) Then $slots = 2 EndIf EndFunc Func thread3() Local $x1 = 0, $y1 = 0 $result = _ImageSearchArea($Image, 1, $WindowX, $WindowY, $WindowX, $WindowY, $x1, $y1, 0, 0) If ($result) Then $slots = 3 EndIf EndFunc Func thread4() Local $x1 = 0, $y1 = 0 $result = _ImageSearchArea($Image, 1, $WindowX, $WindowY, $WindowX, $WindowY, $x1, $y1, 0, 0) If ($result) Then $slots = 4 EndIf EndFunc _GetAvailableSlots()
  10. Here is the idea I'm going for... Whichever thread ends up true = the amount of slots available. #include <authread.au3> _AuThread_Startup() Func _GetAvailableSlots() Global $slots = -1 $thread1 = _AuThread_StartThread("thread1") $thread2 = _AuThread_StartThread("thread2") $thread3 = _AuThread_StartThread("thread3") $thread4 = _AuThread_StartThread("thread4") ConsoleWrite($slots & @CRLF) EndFunc Func thread1() If (True) Then $slots = 1 EndIf EndFunc Func thread2() If (False) Then $slots = 2 EndIf EndFunc Func thread3() If (False) Then $slots = 3 EndIf EndFunc Func thread4() If (False) Then $slots = 4 EndIf EndFunc _GetAvailableSlots()
  11. It really seemed like this was going to be a simple concept.. 😆
  12. I recall seeing this in one of my recent OS classes. Time to get way in over my head and relearn it. Thanks 🙂
  13. Is it possible to have a return value (or message) from a function within the thread?
  14. Hi, this is my first post so if it is in the wrong place I apologize, I'm just looking for some answers here. I've simplified the actual code I'm using into this script: #include <authread.au3> _AuThread_Startup() Func _GetAvailableSlots() Global $slots = -1 $thread1 = _AuThread_StartThread("thread1") ConsoleWrite($slots & @CRLF) EndFunc Func thread1() If (True) Then ToolTip("Yes", 0, 0) $slots = 3 Else ToolTip("No", 0, 0) EndIf EndFunc _GetAvailableSlots() For some reason, the variable $slots prints out as -1 instead of 3. Would anyone have any idea why this is happening? Been stuck on it forever now. Thanks.
×
×
  • Create New...