Lee Bussy Posted June 19, 2008 Share Posted June 19, 2008 (edited) Hello there ... my current project has me a little stumped. I'd like to take an action if someone right-clicks on a button. I am polling for button clicks currently with the following function: Func CheckEvents() ; check for button click $nMsg = GUIGetMsg() Select Case $nMsg = $GUI_EVENT_CLOSE Exit Case $nMsg = $btnOne Return "btnOne" Case $nMsg = $btnTwo Return "btnTwo" Case $nMsg = $btnThree Return "btnThree" Case $nMsg = $btnFour Return "btnFour" EndSelect Return "" EndFunc That works of course but only on left clicks. Is it possible to capture a right-click? I saw the context menu option but that's not what I want ... I need to return a value if there's a right click. EDIT: The function GUICtrlSetOnEvent() looks like what I want, except I want it on a control not on the GUI. EDIT #2: Hrm, found GUI Reference - OnEvent Mode .... researching that now :-) Edited June 19, 2008 by Lee Bussy Link to comment Share on other sites More sharing options...
Lee Bussy Posted June 19, 2008 Author Share Posted June 19, 2008 Okay I tried ... the best i can come up with is this kludgey bit of "art": #include <GUIConstantsEx.au3> Opt("MouseCoordMode", 2) Opt("PixelCoordMode", 2) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $mainwindow = GUICreate("", 200, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") $okbutton = GUICtrlCreateButton("OK", 70, 50, 60) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "RightClick") While 1 Sleep(1000) WEnd Func CLOSEClicked() Exit EndFunc Func RightClick() $pos = MouseGetPos() ;MsgBox(0, "Mouse x,y:", $pos[0] & "," & $pos[1]) If $pos[0] > 70 And $pos[0] < 130 And $pos[1] > 50 And $pos[1] < 75 Then MsgBox(0, "GUI Event", "You right clicked") EndIf EndFunc Is there a better way? Link to comment Share on other sites More sharing options...
NELyon Posted June 19, 2008 Share Posted June 19, 2008 If _IsPressed(02) Then MsgBox(0, "Test", "You right clicked") EndIf Link to comment Share on other sites More sharing options...
Lee Bussy Posted June 19, 2008 Author Share Posted June 19, 2008 If _IsPressed(02) Then MsgBox(0, "Test", "You right clicked") EndIfThanks for the reply KentonBomb. I think maybe I'm missing something or not describing my need correctly. That bit of code should show if the mouse is right-clicked however there's still no way to limit that to the control I wish to check. Right clicking on a control will not "trigger" a control event unless I'm missing something simple. With _IsPressed(02) I'd still need to check location, would I not? Link to comment Share on other sites More sharing options...
Kiti Posted June 20, 2008 Share Posted June 20, 2008 This is exactly what you need: #include <Misc.au3> GUICreate("Hi", 200, 200) GUICtrlCreateLabel("Right click the folowing button!", 20, 20) GUICtrlCreateButton("Hello", 80, 100, 50, 50) GUISetState(@SW_SHOW) While 1 $pos = MouseGetPos() If _IsPressed(02) And 495 < $pos[0] And $pos[0] < 540 And 385 < $pos[1] And $pos[1] < 430 Then MsgBox(0, "Test", "Oh yes!") EndIf Sleep(100) WEnd Replace what's left to "<" sign with your actual button coordinates. If the button doesn't stay in the same place, use client (your GUI in this case) coords. Think outside the box.My Cool Lego Technic Website -- see walking bipeds and much more!My YouTube account -- see cool physics experimentsMy scripts:Minesweeper bot: Solves advanced level in 1 second (no registry edit), very improved GUI, 4 solving stylesCan't go to the toilet because of your kids closing your unsaved important work? - Make a specific window uncloseableCock Shooter Bot -- 30 headshots out of 30 Link to comment Share on other sites More sharing options...
rasim Posted June 20, 2008 Share Posted June 20, 2008 (edited) Lee BussyExample:expandcollapse popup#include <GuiConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <Misc.au3> #include <WinAPI.au3> Global $DllHandle = DllOpen("user32.dll") $hGui = GUICreate("Double Click Demo", 200, 100) $button = GUICtrlCreateButton("start", 60, 35, 75, 23, $BS_NOTIFY) $aBtnPos = ControlGetPos($hGui, "", $button) GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") GUISetState() While GUIGetMsg() <> -3 If _IsPressed("02", $DllHandle) Then $tPoint = _WinAPI_GetMousePos(True, $hGui) $X = DllStructGetData($tPoint, "X") $Y = DllStructGetData($tPoint, "Y") If ($X >= $aBtnPos[0]) And ($X <= $aBtnPos[0] + $aBtnPos[2]) _ And ($Y >= $aBtnPos[1]) And ($Y <= $aBtnPos[1] + $aBtnPos[3]) Then _DebugPrint("Right mouse click", @ScriptLineNumber) Sleep(100) EndIf WEnd DllClose($DllHandle) Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) ;HiWord Local $nID = BitAnd($wParam, 0x0000FFFF) ;LoWord If $nID = $button Then Switch $nNotifyCode Case $BN_CLICKED _DebugPrint("Left mouse click", @ScriptLineNumber) Case $BN_DBLCLK _DebugPrint("Left mouse double click", @ScriptLineNumber) EndSwitch EndIf Return $GUI_RUNDEFMSG EndFunc Func _DebugPrint($s_text, $line = @ScriptLineNumber) ConsoleWrite("+=====================================" & @LF & _ "--> Script Line (" & $line & "):" & @LF & "!" & @TAB & $s_text & @LF & _ "+=====================================" & @LF) EndFunc Edited June 20, 2008 by rasim Link to comment Share on other sites More sharing options...
Lee Bussy Posted June 23, 2008 Author Share Posted June 23, 2008 So basically there is no event generated by a control when you right click - it's all done at the form/GUI level and then I have to check the coordinates of the click. Not as I had hoped, but I can handle it now that I know. Thanks for the replies and showing me more than one way to skin a cat. Should come along swimmingly now. Link to comment Share on other sites More sharing options...
UritOR Posted August 30, 2015 Share Posted August 30, 2015 Well 7 Years passed, i tried to find a solution in google for this problem but still nothing simple...If only it would be _IsPressed(02, $controlName)=(. Anyone knows the easy way without use coordinates ? guiltyking 1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 30, 2015 Moderators Share Posted August 30, 2015 UritORWelcome to the AutoIt forums.In future please do not resurrect threads from this far back - the language has changed so much that it is likely that the functionality has already been incorporated and the previously posted code will almost certainly not run in the current version of AutoIt without modification.And does this help?#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $hGUI = GUICreate("Test", 500, 500) $cButton = GUICtrlCreateButton("Test", 10, 10, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton MsgBox($MB_SYSTEMMODAL, "Pressed", "LEFT") Case $GUI_EVENT_SECONDARYUP $aCInfo = GUIGetCursorInfo($hGUI) If $aCInfo[4] = $cButton Then MsgBox($MB_SYSTEMMODAL, "Pressed", "RIGHT") EndIf EndSwitch WEndM23 UritOR and maniootek 2 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
UritOR Posted October 13, 2015 Share Posted October 13, 2015 Melba23,Thank you, It works. Can it be used in OnEvent gui mode? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 14, 2015 Moderators Share Posted October 14, 2015 UritOR,Of course:expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetOnEvent($GUI_EVENT_SECONDARYUP, "_SecondaryUp") $cButton = GUICtrlCreateButton("Test", 10, 10, 80, 30) GUICtrlSetOnEvent($cButton, "_Button") GUISetState() While 1 Sleep(10) WEnd Func _Button() MsgBox($MB_SYSTEMMODAL, "Pressed", "LEFT") EndFunc Func _SecondaryUp() $aCInfo = GUIGetCursorInfo($hGUI) If $aCInfo[4] = $cButton Then MsgBox($MB_SYSTEMMODAL, "Pressed", "RIGHT") EndIf EndFunc Func _Exit() Exit EndFuncM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
UritOR Posted October 15, 2015 Share Posted October 15, 2015 Thank you. Link to comment Share on other sites More sharing options...
hiepkhachsg Posted March 4, 2016 Share Posted March 4, 2016 At last i found it. Tks Melba23 ! Link to comment Share on other sites More sharing options...
guiltyking Posted April 9, 2016 Share Posted April 9, 2016 (edited) On 3/3/2016 at 5:29 AM, hiepkhachsg said: At last i found it. Tks Melba23 ! That does not help to get GUICtrlRead(@GUI_CtrlId) of right clicked button while you can get it left clicked. not a real solution to button press. expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetOnEvent($GUI_EVENT_SECONDARYUP, "_SecondaryUp") $cButton = GUICtrlCreateButton("Test", 10, 10, 80, 30) GUICtrlSetOnEvent($cButton, "_Button") $cButton2 = GUICtrlCreateButton("Testz", 10, 50, 80, 30) GUICtrlSetOnEvent($cButton2, "_Button") GUISetState() While 1 Sleep(10) WEnd Func _Button() $nTempId=GUICtrlRead(@GUI_CtrlId) $aCInfo = GUIGetCursorInfo($hGUI) MsgBox($MB_SYSTEMMODAL, "Pressed", "LEFT"&$nTempId&$aCInfo) EndFunc Func _SecondaryUp() $aCInfo = GUIGetCursorInfo($hGUI) If $aCInfo[4] = $cButton Then $nTempId=GUICtrlRead(@GUI_CtrlId) ;cannot get MsgBox($MB_SYSTEMMODAL, "Pressed", "RIGHT"&$nTempId&$aCInfo) EndIf If $aCInfo[4] = $cButton2 Then $nTempId=GUICtrlRead(@GUI_CtrlId) ;cannot get MsgBox($MB_SYSTEMMODAL, "Pressed", "RIGHT2"&$nTempId&$aCInfo) EndIf EndFunc Func _Exit() Exit EndFunc very bad solution is for $x=1 to 3 If $aCInfo[4] = $cButton[$x] Then $nTempId=GUICtrlRead(@GUI_CtrlId) ;cannot get $nTempId2=GUICtrlRead($cButton[$x]) ;can get MsgBox($MB_SYSTEMMODAL, "Pressed", "RIGHT"&$nTempId&"::"&$nTempId2) EndIf next Edited April 9, 2016 by guiltyking case study Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 14, 2016 Moderators Share Posted April 14, 2016 guiltyking, As the @GUI_CtrlId macro just holds the ControlID of the last actioned control, why can you not use the $aCInfo[4] value directly? expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Opt("GUIOnEventMode", 1) $hGUI = GUICreate("Test", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetOnEvent($GUI_EVENT_SECONDARYUP, "_SecondaryUp") $cButton = GUICtrlCreateButton("Test", 10, 10, 80, 30) GUICtrlSetOnEvent($cButton, "_Button") $cButton2 = GUICtrlCreateButton("Testz", 10, 50, 80, 30) GUICtrlSetOnEvent($cButton2, "_Button") GUISetState() While 1 Sleep(10) WEnd Func _Button() $nTempId = GUICtrlRead(@GUI_CtrlId) MsgBox($MB_SYSTEMMODAL, "Pressed", "LEFT " & $nTempId) EndFunc ;==>_Button Func _SecondaryUp() $aCInfo = GUIGetCursorInfo($hGUI) Switch $aCInfo[4] Case $cButton $nTempId = GUICtrlRead($cButton) ;can get MsgBox($MB_SYSTEMMODAL, "Pressed", "RIGHT " & $nTempId) Case $cButton2 $nTempId = GUICtrlRead($cButton2) ;can get MsgBox($MB_SYSTEMMODAL, "Pressed", "RIGHT2 " & $nTempId) EndSwitch EndFunc ;==>_SecondaryUp Func _Exit() Exit EndFunc ;==>_Exit M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now