Jump to content

Recommended Posts

Posted

Hello guys. I know how to write a basic clicker, but how would I go about making it do so only within a specified window, so that I may safely leave it in the background without the clicks interfering with what I am doing?

Thank you

Posted

Try this out, I didn't write it and I don't remember where I found it but it works decent.

;===============================================================================
;
; Function Name:  _MouseClickMinimized()
; 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 (cpf: or 2???) to use this without bugs.
; Author(s):      Insolence <insolence_9@yahoo.com>
;
;===============================================================================
Func _MouseClickMinimized($Window, $Button = "left", $X = "", $Y = "", $Clicks = 1, $handle = 0)
    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
    if $handle = 1 Then
        Local $winhandle = $Window
    Elseif $handle = 0 Then
        Local $winhandle = WinGetHandle($Window)
    EndIf
    Select
        Case $Button = "right"
            $Button = $MK_RBUTTON
            $ButtonDown = $WM_RBUTTONDOWN
            $ButtonUp = $WM_RBUTTONUP
        Case $Button = "left"
            $Button = $MK_LBUTTON
            $ButtonDown = $WM_LBUTTONDOWN
            $ButtonUp = $WM_LBUTTONUP
        Case Else  ;; CPF
            ;; illegal number of parameters?
;~             MsgBox(32, "KCH: Problem", "_MouseClickPlus() called with bad number of params?")
            Return
    EndSelect
    ;; makes no sense to send click to minimized window with current mouse coordinates
    If $X = "" Or $Y = "" Then
        ;; illegal number of parameters?
;~         MsgBox(32, "KCH: Problem", "_MouseClickPlus() called with bad number of params?")
        Return
    EndIf
    For $i = 1 To $Clicks
        DllCall("user32.dll", "int", "SendMessage", _
                "hwnd", $winhandle, _
                "int", $WM_MOUSEMOVE, _
                "int", 0, _
                "long", _MakeLong($X, $Y))
        DllCall("user32.dll", "int", "SendMessage", _
                "hwnd", $winhandle, _
                "int", $ButtonDown, _
                "int", $Button, _
                "long", _MakeLong($X, $Y)) 
        Sleep(10)
        DllCall("user32.dll", "int", "SendMessage", _
                "hwnd", $winhandle, _
                "int", $ButtonUp, _
                "int", $Button, _
                "long", _MakeLong($X, $Y)) 
    Next
EndFunc   ;==>_MouseClickMinimized

;===============================================================================
;
; Function Name:  _MouseMoveMinimized()
; Version added:  0.1
; Description:    Sends a move message to window, works minimized.
; Parameter(s):   $Window     =  Title of the window to send click to
;                 $X          =  X coordinate
;                 $Y          =  Y coordinate
; Remarks:        You MUST be in "MouseCoordMode" 0 (cpf: or 2???) to use this without bugs.
; Author(s):      Cris Fuhrman (based on code by Insolence <insolence_9@yahoo.com>)
;
;===============================================================================
Func _MouseMoveMinimized($Window, $X = "", $Y = "", $handle = 0)
    Local $WM_MOUSEMOVE = 0x0200
    Local $i = 0
    if $handle = 1 Then
        Local $winhandle = $Window
    Elseif $handle = 0 Then
        Local $winhandle = WinGetHandle($Window)
    EndIf
    
    If $X = "" Or $Y = "" Then
;~         MsgBox(32, "KCH: Problem", "_MouseMovePlus() called with bad number of params?")
        Return
    EndIf
    
    DllCall("user32.dll", "int", "SendMessage", _
            "hwnd", $winhandle, _
            "int", $WM_MOUSEMOVE, _
            "int", 0, _
            "long", _MakeLong($X, $Y)) 
EndFunc   ;==>_MouseMoveMinimized

Func _MakeLong($LoWord, $HiWord)
    Return BitOR($HiWord * 0x10000, BitAND($LoWord, 0xFFFF))
EndFunc   ;==>_MakeLong
Posted

ControlClick usually works in this cases.. and i have and example of it... the example is the last one

#include <winapi.au3>
If not winexists("[Class:CalcFrame]") then ShellExecute("calc")             ; if calc doesn`t exists, it run it.
Winwait("[Class:CalcFrame]")                                                ; waits until calc exists.
$hndl = WinActivate("[Class:CalcFrame]")                                    ; Active calc, and save the window handle in a variable.
$pos = Controlgetpos("[Class:CalcFrame]","","[CLASS:Button; INSTANCE:5]")   ; Get the position of the button "1".
Msgbox(0,"Position of the button","Position of the control inside the clien area"&@CRLF _
                                    &"The X coord of the control inside the client area is "&$pos[0]&@CRLF _
                                    &"The Y coord of the control inside the client area is "&$pos[1]&@CRLF _
                                    &"The width of the control is "&$pos[2]&@CRLF _
                                    &"The height of the control is "&$pos[3]&@CRLF)
; -----------Preparating the Structure for the function call to get the absolute coords of the control -----------
$tPoint = DllStructCreate($tagPoint)    ; The Struct tagPoint is alreade declared, it has two elements "x" and "y"
DllStructsetdata($tPoint, "x",$pos[0])  ; I put in the element X of the structure the X pos of the control
DllStructsetdata($tPoint, "y",$pos[1])  ; I put in the element Y of the structure the X pos of the control
_WinAPI_ClientToScreen($hndl,$tPoint)

;~ Msgbox(0,"Position of the button","Absolute position of the control"&@CRLF _
;~                                  &"The X coord of the control is "&DllStructgetdata($tPoint, "x")&@CRLF _
;~                                  &"The Y coord of the control is "&DllStructgetdata($tPoint, "y")&@CRLF)

;IF YOU WANT TO SAVE THE DATA INTO VARIABLES YOU SHOULD DO THIS.
$x = DllStructgetdata($tPoint, "x")
$y = DllStructgetdata($tPoint, "y")
$tPoint = 0 ; free the struct.

Msgbox(0,"Position of the button","Absolute position of the control"&@CRLF _
                                    &"The X coord of the control is "&$x&@CRLF _
                                    &"The Y coord of the control is "&$y&@CRLF)
mousemove($x, $y, 15)
sleep(500)
mousemove($x + $pos[2], $y + $pos[3], 15)
sleep(500)
MsgBox(0,"ControlSend","You can send the keys input directly to a control")
ControlSend("[Class:CalcFrame]","","[CLASS:#32770; INSTANCE:1]","123456789")
sleep(1000)
ControlClick("[Class:CalcFrame]","","[CLASS:Button; INSTANCE:13]")
sleep(1000)
For $i = 1 to 9
ControlSend("[Class:CalcFrame]","","[CLASS:#32770; INSTANCE:1]",$i)
sleep(500)
Next
sleep(500)
ControlClick("[Class:CalcFrame]","","[CLASS:Button; INSTANCE:13]")
sleep(500)
MsgBox(0,"Non active window try","Now we gonna try to do this but with the window minimized")
sleep(500)
winsetstate("[Class:CalcFrame]","",@SW_MINIMIZE)
sleep(500)
For $i = 9 to 1 step -1
ControlSend("[Class:CalcFrame]","","[CLASS:#32770; INSTANCE:1]",$i)
sleep(500)
Next
Msgbox(0,"It is the end","This is the end of the demostration, good look")

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...