Jump to content

Detecting right mouse click on button


creeping
 Share

Recommended Posts

There's probly a better way to do it, but you could do similar for any type of control , not just buttons..

#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 0)

$Main = GuiCreate("MyGUI", 141, 128,-1, -1)

$Button_1 = GuiCtrlCreateButton("Button1", 30, 20, 80, 30)
GUICtrlSetOnEvent($Button_1, 'ButtonID')
$Button_2 = GuiCtrlCreateButton("Button2", 30, 70, 80, 30)
GUICtrlSetOnEvent($Button_2, 'ButtonID')

GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, 'ButtonID',$Main)
GUISetOnEvent($GUI_EVENT_CLOSE, 'ButtonID',$Main)

GuiSetState()

While 1
    Sleep(10)
WEnd

Func ButtonID()
    Select
        Case @GUI_CTRLID = $GUI_EVENT_SECONDARYDOWN
            $mp = MouseGetPos()
            If ($mp[0] > 33 and $mp[0] < 114) And ($mp[1] > 48 And $mp[1] < 78) Then
                MsgBox(0,'', 'Button1 was Right Clicked')
            ElseIf ($mp[0] > 33 and $mp[0] < 114) And ($mp[1] > 99 And $mp[1] < 130) Then
                MsgBox(0,'', 'Button2 was Right Clicked')
            EndIf
        Case @GUI_CTRLID = $Button_1
            MsgBox(0,'','Button1 was Left Clicked')
        Case @GUI_CTRLID = $Button_2
            MsgBox(0,'','Button2 was Left Clicked')         
        Case @GUI_CTRLID = $GUI_EVENT_CLOSE
            Exit
    EndSelect
EndFunc

Cheers

Edited by smashly
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...