Jump to content

right clicking controls


Recommended Posts

How do I know if a control is right clicked in a gui? I try this but it is not right.

#include <GUIConstants.au3>

Opt("GUICoordMode",2)
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)

$parent1 = GUICreate("Parent1")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "SpecialEvents");Here;;;;;;;;;;;;


$ok1 = GUICtrlCreateButton ("OK",  10, 30, 50)
GUICtrlSetOnEvent(-1, "OKPressed")

$cancel1 = GUICtrlCreateButton ( "Cancel",  0, -1)
GUICtrlSetOnEvent(-1, "CancelPressed")

GUISetState(@SW_SHOW)


While 1
    Sleep(10)
Wend

Func OKPressed()
    MsgBox(0, "OK Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE & " CtrlHandle=" & @GUI_CTRLHANDLE)
EndFunc

Func CancelPressed()
    MsgBox(0, "Cancel Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE & " CtrlHandle=" & @GUI_CTRLHANDLE)
EndFunc

Func SpecialEvents()    

    Select
        Case @GUI_CTRLID = $GUI_EVENT_CLOSE
            MsgBox(0, "Close Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
            Exit
            
        Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
            MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
            
        Case @GUI_CTRLID = $GUI_EVENT_RESTORE
            MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE)
        
        Case @GUI_CTRLID = $GUI_EVENT_SECONDARYDOWN; and here;;;;;;;is what i tried
            $ctrlfocus = ControlGetFocus($parent1,"parent1")
            MsgBox(0, "ControlGetFocus is " & $ctrlfocus,"ControlGetFocus is " & $ctrlfocus)    
    EndSelect   
EndFunc

.

Link to comment
Share on other sites

  • Moderators

What's not working? I get the message box with whatever has focus at the moment. I would change this:

$ctrlfocus = ControlGetFocus($parent1,"parent1")
To this:
$ctrlfocus = ControlGetFocus($parent1)

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

What's not working? I get the message box with whatever has focus at the moment. I would change this:

$ctrlfocus = ControlGetFocus($parent1,"parent1")
To this:
$ctrlfocus = ControlGetFocus($parent1)
Thank you, but that did not do it either. It only gets the button that was last left click, both ways.

.

Link to comment
Share on other sites

I found a workaround.... I'm sure theres a better way. Insert this under the @GUI_CTRLID = $GUI_EVENT_SECONDARYDOWN

Opt("MouseCoordMode", 0)

$pos = MouseGetPos()
            Select
                Case $pos[1]<75 AND $pos[1]>50
                    
                    Select
                        Case $pos[0]<50 AND $pos[0]>8
                            ControlFocus("Parent1", "", 3)
                        Case $pos[0]<108 AND $pos[0]>58
                            ControlFocus("Parent1", "", 4)
                    EndSelect
            EndSelect
            $ctrlfocus = ControlGetFocus($parent1)
            MsgBox(0, "ControlGetFocus is " & $ctrlfocus,"ControlGetFocus is " & $ctrlfocus)
Link to comment
Share on other sites

I found a workaround.... I'm sure theres a better way. Insert this under the @GUI_CTRLID = $GUI_EVENT_SECONDARYDOWN

Opt("MouseCoordMode", 0)

$pos = MouseGetPos()
            Select
                Case $pos[1]<75 AND $pos[1]>50
                    
                    Select
                        Case $pos[0]<50 AND $pos[0]>8
                            ControlFocus("Parent1", "", 3)
                        Case $pos[0]<108 AND $pos[0]>58
                            ControlFocus("Parent1", "", 4)
                    EndSelect
            EndSelect
            $ctrlfocus = ControlGetFocus($parent1)
            MsgBox(0, "ControlGetFocus is " & $ctrlfocus,"ControlGetFocus is " & $ctrlfocus)
Thats a big work around, thanks for the help though. I don't think there is any good way to do this. There may be a DLL way to do this, but I am no good with DLLs.

.

Link to comment
Share on other sites

  • Moderators

Thank you, but that did not do it either. It only gets the button that was last left click, both ways.

It wasn't intended to do "anything", it was a visual correction I thought you should make because if the title ever changed, then that function would not work at all. Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I re-visited this problem and I came up with a really simple solution that I can't believe I missed. Is this what you are looking for?

(in the While loop)

Case @GUI_CTRLID = $GUI_EVENT_SECONDARYDOWN; and here;;;;;;;is what i tried
            $pos = GuiGetCursorInfo()
            MsgBox(0, "ControlGetFocus", "ControlGetFocus is " & $pos[4])

$pos[4] is the control that the mouse is hovering over. You could easily give it focus with the code I posted earlier, above.

Regards,

Link to comment
Share on other sites

I re-visited this problem and I came up with a really simple solution that I can't believe I missed. Is this what you are looking for?

(in the While loop)

Case @GUI_CTRLID = $GUI_EVENT_SECONDARYDOWN; and here;;;;;;;is what i tried
            $pos = GuiGetCursorInfo()
            MsgBox(0, "ControlGetFocus", "ControlGetFocus is " & $pos[4])

$pos[4] is the control that the mouse is hovering over. You could easily give it focus with the code I posted earlier, above.

Regards,

Thank you for the help.

.

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...