Jump to content

MouseClickWait() UDF


lte5000
 Share

Recommended Posts

;===============================================================================

;

; Description:      Wait for a LEFT mouse click within a certain area on the screen.

;Takes advantage of the WinSetTrans() function (Win2000/XP).

;Thanks to CyberSlug for the idea.

; Syntax:              _MouseClickWait($iLeftPos, $iTopPos, $x, $y)

; Parameter(s):    $iLeftPos            - The LEFT side of the click detecting area.

;                          $iTopPos            - The TOP of the click detecting area.

;                          $x                    - The WIDTH of the click detecting area.

;                          $y                    - The HEIGHT of the click detecting area.

; Requirement(s):  AutoIt v3.0.103 unstable on Win2000/XP 

; Return Value(s):  0 - If click detecting area (GUI) is somehow closed before receiving a click or OS is not Win2000/XP.

;                          Otherwise it returns 1.

; Author(s):          Kendall Martin (lte5000)

; Note(s):            It attempts to pass on the mouse click, but it will not pass on keystrokes that the user presses...

;

;==============================================================================

Func _MouseClickWait($iLeftPos, $iTopPos, $x, $y)

        ;Wrong OS.

        If @OSVersion = "WIN_NT4" Or @OSType = "WIN32_WINDOWS" Then Return 0

        ;Local variables.

        Local $iButtonHook, $iMousePos, $iLeftPos, $iTopPos, $x, $y

        ;GUI options.

        Opt("GUICoordMode", 1)

        Opt("GUINotifyMode", 1)

        Opt("GUITaskbarEntry", 0)

        ;Create GUI.

        GUICreate("MouseHook", $x, $y, $iLeftPos, $iTopPos, 0x80000000 + 0x400000)

        ;Set a button on the GUI.

        $iButtonHook = GUISetControl("button", "", $iLeftPos, $iTopPos, $x, $y)

        ;Show GUI.

        GUIShow()

        ;Set translucent GUI.

        WinSetTrans("MouseHook", "", 1)

        ;Wait for a click in the selected area.

        While 1

                $msg = GuiMsg(0)

                Select

                        ;GUI was closed.

                        Case $msg = -3

                                ;Return 0.

                                Return 0

                                ;Set @error to 0.

                                SetError(1)

                        ;Area was clicked.

                        Case $msg = $iButtonHook

                                ;Get mouse position.

                                $iMousePos = MouseGetPos()

                                ;Delete GUI.

                                GUIDelete()

                                ;Pass on mouse click.

                                MouseClick("left",  $iMousePos[0], $iMousePos[1], -1, 0)

                                ;Return 1.

                                Return 1

                EndSelect

                ;Make sure GUI stays activated.

                WinActivate("MouseHook")

                ;Free CPU time.

                Sleep(30)

        Wend

EndFunc

MsgBox(0, "Return from _MouseClickWait", _MouseClickWait(0, 0, 1000, 100))
Edited by lte5000
Link to comment
Share on other sites

Here's a slightly different approach.... Works decently for left mouse click, but right-button and keyboard stuff doesn't work very well... Also, start menu and tray tip don't display....

HotKeySet("{Pause}", "Terminate")
Func Terminate()
   Exit
EndFunc

Dim $iButtonHook, $iMousePos
Dim $iLeftPos = 0, $iTopPos = 0, $x = @DesktopWidth-00, $y = @DesktopHeight-00

Opt("GUICoordMode", 1)
Opt("GUINotifyMode", 1)
Opt("GUITaskbarEntry", 0)

GUICreate("MouseHook", $x, $y, $iLeftPos, $iTopPos, 0x80000000 + 0x400000)
$iButtonHook = GUISetControl("button", "", -10, -10, $x+100, $y+100)
GUIShow()

WinSetTrans("MouseHook", "", 100) ;use higher value for debugging; 1 for real use
WinSetOnTop("MouseHook","", 1)  ;topmost window

;Wait for a click in the selected area.
While 1
    If $iButtonHook = GuiMsg(0) Then
     $iMousePos = MouseGetPos();Get mouse position.
     GUIHide()
    ;sleep(1000)
    ;Send click twice because 1 activates the window and 2 actually registers the click...
     MouseClick("left",  $iMousePos[0], $iMousePos[1], 1, 0);Pass on mouse click.
    ;sleep(1000)
    ;MouseClick("left",  $iMousePos[0], $iMousePos[1], 1, 0);Pass on mouse click.
    ;sleep(1000)
     GuiShow()
     TrayTip("Click!", '(' & $iMousePos[0] & ',' & $iMousePos[1] & ')' , 5)
  EndIf
Wend
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
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...