;================================================================================================= ; Function: _PostMessage_ClickDrag($hWnd, $X1, $Y1, $X2, $Y2, $Button = "left") ; Description: Sends a mouse click and drag command to a specified window. ; Parameter(s): $hWnd - The handle or the title of the window. ; $X1, $Y1 - The x/y position to start the drag operation from. ; $X2, $Y2 - The x/y position to end the drag operation at. ; $Button - (optional) The button to click, "left", "right", "middle". Default is the left button. ; $Delay - (optional) Delay in milliseconds. Default is 50. ; Requirement(s): A window handle/title. ; Return Value(s): On Success - Returns true ; On Failure - Returns false ; @Error - 0 = No error. ; 1 = Invalid window handle or title. ; 2 = Invalid start position. ; 3 = Invalid end position. ; 4 = Failed to open the dll. ; 5 = Failed to send a MouseDown command. ; 5 = Failed to send a MouseMove command. ; 7 = Failed to send a MouseUp command. ; Author(s): KillerDeluxe ;================================================================================================= Func _PostMessage_ClickDrag($hWnd, $X1, $Y1, $X2, $Y2, $Button = "left", $Delay = 50) If Not IsHWnd($hWnd) And $hWnd <> "" Then $hWnd = WinGetHandle($hWnd) EndIf If Not IsHWnd($hWnd) Then Return SetError(1, "", False) EndIf If Not IsInt($X1) Or Not IsInt($Y1) Then Return SetError(2, "", False) EndIf If Not IsInt($X2) Or Not IsInt($Y2) Then Return SetError(3, "", False) EndIf If StringLower($Button) == "left" Then $Button = $WM_LBUTTONDOWN $Pressed = 1 ElseIf StringLower($Button) == "right" Then $Button = $WM_RBUTTONDOWN $Pressed = 2 ElseIf StringLower($Button) == "middle" Then $Button = $WM_MBUTTONDOWN $Pressed = 10 If $Delay == 10 Then $Delay = 100 EndIf $User32 = DllOpen("User32.dll") If @error Then Return SetError(4, "", False) DllCall($User32, "bool", "PostMessage", "hwnd", $hWnd, "int", $Button, "int", "0", "long", _MakeLong($X1, $Y1)) If @error Then Return SetError(5, "", False) Sleep($Delay / 2) DllCall($User32, "bool", "PostMessage", "hwnd", $hWnd, "int", $WM_MOUSEMOVE, "int", $Pressed, "long", _MakeLong($X2, $Y2)) If @error Then Return SetError(6, "", False) Sleep($Delay / 2) DllCall($User32, "bool", "PostMessage", "hwnd", $hWnd, "int", $Button + 1, "int", "0", "long", _MakeLong($X2, $Y2)) If @error Then Return SetError(7, "", False) DllClose($User32) Return SetError(0, 0, True) EndFunc ;Send (_MouseClickPlus) ;_MouseClickPlus( "Diablo II", "left", 525 - $borderwidth, 585 - $TitleHeight ) 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