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

    • Pike
      By Pike
      Hello Everyone,
      New Guy here. This is a two-part question, hopefully easy enough though. I know it's ugly coding, this is because I have only a couple hours worth of coding experience and could really use some help.
      1) When I single click the button I want one action (like playing a sound clip) and when I double click the button I want a different action (such as opening dialogue box to ask for soundclip directory address). At the bottom of the script I made a comment which one I would like single click versus double click.
      2) I can not get the FileOpenDialogue to save the file address to the config.ini file at the 'One' position on the .ini.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include <AutoItConstants.au3> #include <Sound.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) Global $OneID _Main() Func _Main() GUICreate("Form1", 156, 86, 281, 276) $OneID = GUICtrlCreateButton("Button", 15, 17, 122, 37) GUICtrlSetOnEvent($OneID, "OnOne") GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") GUISetState() While 1 While 1 Sleep(1000) WEnd WEnd EndFunc ;---------------Functions------------- While 1 Sleep(100) WEnd Func OnOne() ; ******************Single Click for this action**************** $OneID = IniRead("config.ini", "Config", "One", $OneID) If $OneID = True Then SoundPlay($OneID, @HotKeyPressed) Else ; *******Double Click for this action*****And Help Saving File Address to config.ini 'One'*********** $OneID = FileOpenDialog("Select file", @WorkingDir, "All (*.*)") IniWrite("config.ini", "Config", "One", $OneID) $OneID = InputBox("Enter Information", "Short Name for File?", "") IniWrite("config.ini", "Config", "NameOne", $OneID) EndIf EndFunc Any help would be greatly appreciated, and if you need anymore clarity as to what exactly I'm trying to do, please do not hesitate to ask. Thanks so much!
      Pike
    • kcvinu
      By kcvinu
      Hi all,
      I have a button created with _GUICtrlButton_Create function. I know that this function returns a handle of button instead of an ID. So i have obtain control ID by calling _WinAPI_GetDlgCtrlID function. After that i have tried the GUICtrlSetBkColor function. But it didnt worked. Any suggestions will be appreciated. Thanks in advance. 
      Note : - The window which carries this button is not created with native gui create function. Instead, it is created with CreateWindowEx api function.
    • Robdog1955
      By Robdog1955
      I'm trying to click a button on a web page. I have added a couple of MsgBox lines to allow me to watch what happens on the page. As you can see the first half of my script enters data into text boxes on the page. I have no problem there. I just cannot click on the region buttons. The "set focus" line causes an outline to appear around the EU button and the "click button" line causes the "Pick a Region" text to disappear. Here is the code I have so far.
      #include <IE.au3> Local $oIE = _IECreate("http://questchecker.com/") Local $iQuestID = "123456" Local $sCharacterName = "CharacterName" Local $colForms = _IEFormGetCollection($oIE) $iCount = 0 For $oForm In $colForms $oFormElements = _IEFormElementGetCollection($oForm) For $oFormElement In $oFormElements $iCount = $iCount + 1 Local $sTagName = StringLower($oFormElement.tagName) Local $sElementType = $oFormElement.type Local $sElementName = $oFormElement.name Switch $iCount Case 6 _IEFormElementSetValue($oFormElement, "MyRealm", 0) ; realm Case 7 _IEFormElementSetValue($oFormElement, $sCharacterName, 0) Case 8 _IEFormElementSetValue($oFormElement, $iQuestID, 0) EndSwitch Next Next Local $oButtons = _IEGetObjByName($oIE, "questForm") For $oButton In $oButtons If _IEFormElementGetValue($oButton) = "US" Then MsgBox(0, "", "Click Okay to set focus") _IEAction($oButton, "focus") MsgBox(0, "", "Click Okay to click button") _IEAction($oButton, "click") ExitLoop EndIf Next MsgBox(0, "", "Click Okay to quit") _IEQuit($oIE) Exit  
    • thoms
      By thoms
      Hello Forum,
      As said in the title, I'm searching a way to disable all tabstops in a GUI. My GUI includes 15 buttons and 3 edit controls.
      My questions:
      - is there a way to disable all tabstops at a time
      - is there a way to list all controls of a GUI and then disable tabstops one by one
      - or should I use the following line after each button creation:
      _WinAPI_SetWindowLong(GUICtrlGetHandle(-1), $GWL_STYLE, BitAND(_WinAPI_GetWindowLong(GUICtrlGetHandle(-1), $GWL_STYLE), BitNOT($WS_TABSTOP))) Thanks in advance for your valuable help!
      Thoms
      Edit: or maybe disable TAB key? I don't remember how to do!
    • AppSoftwareVld
      By AppSoftwareVld
      Hello,
       
      I need this for a project and I don't find a method for the next problem.
      I want when I click a button to create a variable ("$variable1") so if I press one more time to create one more ("$variable2") and create more and more how many times you press the button.
       
      Do you have an idea ? 
      Thank you for your attention !
×