Jump to content

Knowing when a Button is clicked.


Kruxe
 Share

Recommended Posts

Hi All,

 

i was wondering if there is a way to know when a button is clicked by using its handle? I have an application I am monitoring and want my script to fire when a specific button is clicked. i can retrieve the buttons handle buy using ControlGetHandle but am having issues figuring what syntax to use to have the script watch for that handle to be used. I have also tried to use _GUICtrlButton_GetState to get the state of the button but this only ever returns a 0. Can anyone guide me in the right direction? Thanks in advanced!

Link to comment
Share on other sites

There is multiple ways to achieve this.  But without a basic snippet of your code, it is hard to suggest one solution.

Maybe _IsPressed ("01") could be an easy way to detect mouse clicks ?

Otherwise,  mouse rawinput, or mouse hook ?

Link to comment
Share on other sites

Hello Again @Nine 

bellow is a snippet of the code. Essentially there are 3 scenarios that will trigger the execution of the external app im monitoring. 1st is a keyboard shortcut the second is opening a child window and the third is the one im struggling with because i have to somehow monitor the execution button. I cant just have a mouse click "01" because then any mouse click will trigger the script. what would you suggest? is there anything i can do with ControlGetHandle()? Thanks for your time!

 

Local $control = ("11")
Local $Q = ("51")
Local $EXECUTE = ControlGetHandle("[CLASS:WilcoxAssociatesIncPC-DMISWndClass]","QuickMeasure","[CLASS:ToolbarWindow32; INSTANCE:5]")




While 1

If _IsPressed($control) And _IsPressed($Q) = True Then

    _CycleStart()

ElseIf  WinExists("Multiple Execution Wizard") = True Then

    _CycleStartMulti()

ElseIf _IsPressed("01") = true Then

    _CycleStart()

EndIf

WEnd

 

Link to comment
Share on other sites

I made it work with my own GUI, you just need to replace with yours :

#include <Misc.au3>
#include <WinAPISysWin.au3>

Local $hWnd = WinGetHandle("My GUI")
Local $EXECUTE = ControlGetHandle($hWnd, "", 3)

While True
  If WinActive ($hWnd) And _IsPressed("01") Then
    $aPos = MouseGetPos()
    $tRect = _WinAPI_GetWindowRect($EXECUTE)
    If $aPos[0] >= DllStructGetData ($tRect,"left") And $aPos[0] <= DllStructGetData ($tRect,"right") And _
      $aPos[1] >= DllStructGetData ($tRect,"top") And $aPos[1] <= DllStructGetData ($tRect,"bottom") Then
      While _IsPressed("01")
        Sleep (100)
      WEnd
      ConsoleWrite ("clicked" & @CRLF)
    EndIf
  EndIf
  Sleep (100)
WEnd

 

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