Jump to content

Clicking at position x-y in a minimized window


 Share

Recommended Posts

I have searched these forums for a view days now and the only example i can find doesn't work or need some tweaking.

Basically i need a function/example on how to send a "mouseDown" and a "mouseUp" function call to a window that doesn't have focus(or even minimized)? I want to send mouse events to a specific window while i use my mouse on different tasks....Is that possible?

It seems this function should work, but it doesn't(atleast for me it does nothing):

;===============================================================================
;
; Function Name: _MouseClickPlus()
; Version added: 0.1
; Description: Sends a click to window
; 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>
;
;===============================================================================
Func _MouseClickPlus($Window, $Button = "left", $X = "", $Y = "", $Clicks = 1)
    MsgBox(1, "", "112333")
    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  ;==>_MouseClickPlus

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

Regards,

Lexart.

Take it from this Quadriplegic, life is beautiful. Don't know what a quadriplegic is? Check out my short bio.Starting an online business.

Link to comment
Share on other sites

As I understand it, this function is written mainly for games where everything happens in its own window (with no controls). For the next example it should work. Try it.

#Include <WinAPI.au3>

Global Const $WM_LBUTTONDOWN = 0x0201

GUICreate('MyGUI', 400, 400)
GUIRegisterMsg($WM_LBUTTONDOWN, 'WM_LBUTTONDOWN')
GUISetState()

Do
Until GUIGetMsg() = -3

Func WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)

    Local $hDC = _WinAPI_GetDC($hWnd)

    For $i = -3 To 3
        For $j = -3 To 3
            DllCall('gdi32.dll', 'int', 'SetPixelV', 'hwnd', $hDC, 'int', _WinAPI_LoWord($lParam) + $i, 'int', _WinAPI_HiWord($lParam) + $j, 'dword', 0x0000FF)
        Next
    Next
    _WinAPI_ReleaseDC($hWnd, $hDC)
    Return 0
EndFunc   ;==>WM_LBUTTONDOWN

But for the MS Paint (for example) that will not work. Here you should replace

WinGetHandle($Window)

to

ControlGetHandle(WinGetHandle($Window), '', '[CLASS:Afx:1000000:8;INSTANCE:1]')

Meaning understood?

Link to comment
Share on other sites

In which window you want to click? Post screenshot of it.

Actually it is for a game....I'm trying to automate walking in the game by holding the middle-mouse button and panning left or right. While that is taking place i want the mouse free to let me do other tasks. I need some sort of way of sending mouse calls to an inactive window in the same way as you can send keys to it(like Autohotkey).

regards.

Take it from this Quadriplegic, life is beautiful. Don't know what a quadriplegic is? Check out my short bio.Starting an online business.

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...