Jump to content
Sign in to follow this  
mike1234

Using Mouseclick as logic

Recommended Posts

mike1234

I have tried to do my due diligance but can not find a way to use the mouse click as a qualifier for logic in code. Can anyone give me an example of using right and/or left mouse click as an intilizer of a function. Similar to a hot key can I say if the user right clicks at anywhere in these coordinates do function A, if they left click in any of these coordinates do function B?

Thanks

Share this post


Link to post
Share on other sites
mike1234

But doesnt _IsPressed only monitor for clicks. The right click still registers on the system so for instance in the app I am trying to interface with the right click menu still launches.

Share this post


Link to post
Share on other sites
JRowe

Check out this UDF:

http://www.autoitscript.com/forum/index.php?showtopic=64738

It allows you to handle mouse events. It's very easy, I recommend playing with the examples first to see how they work. Good luck. :)

Disabling a program's context menu might not be the best idea in the world, because you're tearing a chunk of intended functionality out of it. A hotkey launched menu might be a better route.

Share this post


Link to post
Share on other sites
Malkey

I have tried to do my due diligance but can not find a way to use the mouse click as a qualifier for logic in code. Can anyone give me an example of using right and/or left mouse click as an intilizer of a function. Similar to a hot key can I say if the user right clicks at anywhere in these coordinates do function A, if they left click in any of these coordinates do function B?

Thanks

This is a method.

;
#include <Misc.au3>

Opt("MouseCoordMode", 1) ;1=absolute, 0=relative, 2=client

Do
    $aMP = MouseGetPos() ; For ToolTip use

    Select
        Case _IsPressed("1B"); Esc to exit
            Exit
        Case _WinAPI_PtInRectEx($aMP[0], $aMP[1], 0, 0, 200, 200); Top left corner of Screen
            ToolTip("Target Area")
            Select
                Case _IsPressed("01")
                    Do
                        Sleep(10)
                    Until Not _IsPressed("01")
                    ToolTip("")
                    MsgBox(0, "", "Left mouse button pressed within target area", 3, WinGetHandle(""))
                Case _IsPressed("02")
                    Do
                        Sleep(10)
                    Until Not _IsPressed("02")
                    MsgBox(0, "", "Right mouse button pressed within target area", 3, WinGetHandle(""))
            EndSelect
        Case Not _WinAPI_PtInRectEx($aMP[0], $aMP[1], 0, 0, 200, 200)
            ToolTip("")
    EndSelect
    Sleep(10)
Until 0


Func _WinAPI_PtInRectEx($iX, $iY, $iLeft, $iTop, $iWidth, $iHeight)
    Local $aResult, $tagREC = "int Left;int Top;int Right;int Bottom"
    Local $tRect = DllStructCreate($tagREC)
    DllStructSetData($tRect, "Left", $iLeft)
    DllStructSetData($tRect, "Top", $iTop)
    DllStructSetData($tRect, "Right", $iLeft + $iWidth)
    DllStructSetData($tRect, "Bottom", $iTop + $iHeight)
    $aResult = DllCall("User32.dll", "int", "PtInRect", "ptr", DllStructGetPtr($tRect), "int", $iX, "int", $iY)
    If @error Then Return SetError(@error, 0, False)
    Return $aResult[0] <> 0
EndFunc   ;==>_WinAPI_PtInRectEx
;

Share this post


Link to post
Share on other sites
mike1234

Excelent should be all the info I need.

Thanks

Share this post


Link to post
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
Sign in to follow this  

×