Jump to content
Sign in to follow this  
guiltyking

Check RightClick on a Button

Recommended Posts

guiltyking

Is there any better solution to check right Click on a button rather than that one? Since could be there 100`s keys to process.

Topic is about to find out what is missing in AutoIT to handle contol ID`s of right Clicked Buttons amongst bunch of buttonkeys.

#include <GUIConstantsEx.au3> 

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Test", 300, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "bye")
    GUISetOnEvent($GUI_EVENT_SECONDARYUP, "_SecondaryUp")
    global $cButton[9]
        for $x=1 to 3
            $cButton[$x] = GUICtrlCreateButton("Check"&$x, 10, 10*($X*5), 80, 30)
            GUICtrlSetOnEvent(-1, "_Button")
        next 
        $x+=1
            $cButton[$x] = GUICtrlCreateButton("NoCheck", 10, 10*($X*5), 80, 30)
    GUISetState()
While Sleep(10)
WEnd 

Func _Button()
    $nTempId=GUICtrlRead(@GUI_CtrlId) ; can get ID from Left Clicked Button//
    $aCInfo = GUIGetCursorInfo($hGUI)
    MsgBox(0, "Pressed",  "LEFT "&$nTempId&":"&GUICtrlRead($aCInfo[4]),.5)
EndFunc 

Func _SecondaryUp()
    $aCInfo = GUIGetCursorInfo($hGUI)
    for $x=1 to 3                               ; my solutionprocess slower....
        If $aCInfo[4] = $cButton[$x] Then
            $nTempId=GUICtrlRead(@GUI_CtrlId) ;cannot get  real ID, but last one.
            $nTempId2=GUICtrlRead($cButton[$x]) ;can get  ID            
            MsgBox(0, "Pressed", "RIGHT   "&$nTempId&":<=?  True= "&$nTempId2,1)
        EndIf
    next 
EndFunc 

Func bye()
    Exit
EndFunc

 

Edited by guiltyking

Share this post


Link to post
Share on other sites
InunoTaishou
#include <GUIConstants.au3>
#include <GuiMenu.au3>
#include <WindowsConstants.au3>
#include <WinAPIShellEx.au3>

Global Enum $idSettings = 1000
Global $hMain = GUICreate("", 120, 50)
Global $btnMenu = GUICtrlCreateButton("Menu", 10, 10, 100, 30)
Global $hBtnMenu = GUICtrlGetHandle($btnMenu)
Global $pButtonProc = DllCallbackGetPtr(DllCallbackRegister("ButtonProc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr"))

GUISetState(@SW_SHOW, $hMain)

_WinAPI_SetWindowSubclass($hBtnMenu, $pButtonProc, 1000)

While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            GUIDelete($hMain)
            Exit 0
    EndSwitch
WEnd

Func ButtonProc($hWndFrom, $iMsg, $wParam, $lParam, $iSubclassId, $pData)
    Switch ($hWndFrom)
        Case $hBtnMenu
            Switch ($iMsg)
                Case $WM_RBUTTONUP
                    Local $hMenuButton = _GUICtrlMenu_CreatePopup($MNS_NOCHECK)
                    _GUICtrlMenu_AddMenuItem($hMenuButton, "Settings", $idSettings)
                    _GUICtrlMenu_TrackPopupMenu($hMenuButton, $hWndFrom)
                    _GUICtrlMenu_DestroyMenu($hMenuButton)
            EndSwitch
    EndSwitch
    Return _WinAPI_DefSubclassProc($hWndFrom, $iMsg, $wParam, $lParam)
EndFunc   ;==>EditProc

 

Edited by InunoTaishou

Share this post


Link to post
Share on other sites
guiltyking
Quote
Case $hBtnMenu

how come you can multiple that then? mine still better and shorter.

Edited by guiltyking

Share this post


Link to post
Share on other sites
InunoTaishou

Typo, it was supposed to be Switch ($hWndFrom)

I don't know about better. I'm getting the handle of the button that was clicked from windows as well as every message that button can send to your gui.

Share this post


Link to post
Share on other sites
qwert

Here's a short method I've used now and then:

#include <GUIConstantsEx.au3>

$hGui = GUICreate("Test GUI", 300, 200)
$send = GUICtrlCreateLabel("Test Label", 20, 40, 100, 40)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $send
            MsgBox(0, "Label", "Clicked", 1)
        Case $GUI_EVENT_SECONDARYUP
            $aCur = GUIGetCursorInfo($hGui)
            If IsArray($aCur) Then
                If $aCur[4] = $send Then
                    MsgBox(0, "Label", "Right Clicked", 1)
                EndIf
            EndIf
    EndSwitch
WEnd

Sometimes the method just depends on what other processing you need to include.

Share this post


Link to post
Share on other sites
guiltyking

examine my code, it restricts right click on only selected buttons.

And GUIGetCursorInfo($hGui) fails on multiple keys. therefore you have to loop like mine:)

Edited by guiltyking

Share this post


Link to post
Share on other sites
qwert

I'm curious: what's the advantage of restricting over ignoring?

But, like I said, it depends on what other processing you need.

Regardless, I can imagine that your topic title will result in a lot of people looking for a minimal method ... and maybe the complicated ones, too.

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  

  • Similar Content

    • XinYoung
      By XinYoung
      Quick question: How can I click this "Select All" button in IE? There's no ID, and the href is "#"  
      Am I looking at the wrong html code?
      Am I looking
      Thank you all in advance!
    • XinYoung
      By XinYoung
      Hello again 
      I need to click this Submit button, but it's in a lightbox and has no ID (i think) and I can't figure out a way to target it. _IEFormSubmit doesn't work.

       
      Thank you
    • nooneclose
      By nooneclose
      Hello again, I am in phase two of my help bot. I cannot figure out how to properly code Autoit to click on a webpage button using the I.E UDF. I want to click on the button that I have attached as an image. This button does not have a name but it has an ID. Here is the HTML code for this button that I found using chromes developer inspector.
      HTML Code: 
      <img role="button" tabindex="-1" id="toolactions_INSERT-tbb_image" src="nav_icon_insertkey.gif" alt="New Work Order CTRL+ALT+I" draggable="false"> Here is the code that I have so far:
      ;******************************************************************************* ; Opens IE and fill out a New Workorder ;******************************************************************************* ; Start IE at the ** Tracking Application in ****** $oIE = _IECreate("https:I_am_Bound_by_my_company_to_not_reveal_this_webpage") ; Wait for a browser page load to complete _IELoadWait($oIE) Sleep(6000) ; Store the field names where the important data will be sent Local $nWorkOrderB = _IEGetObjById($oIE, "toolactions_INSERT-tbb_image") _IEAction($nWorkOrderB, "click")  I want my program to click on the button that looks like a piece of paper with a blue # 
      (For those wondering, I am allowed to send images just not the URL.) 
      As always any help would be appreciated. 

    • MJ36
      By MJ36

      How to click this button ? 
      I Try 
       
      func test () $oCorrectObj = "" $tags = $oIE.document.GetElementsByTagName("button") For $tag in $tags $class_value = $tag.GetAttribute("type") If string($class_value) = "buttont" Then $oCorrectObj = $tag MsgBox(0, "Level: ", "Level found :)") Else MsgBox(16, "Failed", "Not found.") ExitLoop EndIf Next If IsObj ( $oCorrectObj ) Then _IEAction ($oCorrectObj, "click") EndIF  
      and
       
      func klik () Local $oFound = "" Local $oBtns = _IETagNameGetCollection($oIE, "span") For $oBtn In $oBtns If String($oBtn.classname) = "yt-uix-button-content" Then $oFound = $oBtn EndIf Next _IEAction ($oFound, "click") EndFunc  
      Please Help 
      Can you click it by name?
    • faustf
      By faustf
      i guys , like title anyone  have idea if is possible , and if yes if  have example to post ?  i find in forum and in google but  i dont know   how can start  to create  button with icon over toolbar near  clock or is  goog before language layout .
      sorry i not post any script but i dont know  where to start
      thankz
      at  all
×