Jump to content

how do I detect mouse clicks on a controlID?


Recommended Posts

Control in your gui or an external app.? If your gui look at GUICtrlSetOnEvent(), if external app, what Lar said.

lol.... damn.

yes its an external app.

I've been trying to look up hook in the help file.

I found the folder: user defined functions / WinAPI Management. Am I looking up the right stuff?

I haven't found any descent tutorials yet but I'll keep searching, it doesn't sound like its an easy topic to talk about?

Link to comment
Share on other sites

Here is a script I made to check whether my mouse is over the font size control in wordpad (ie load wordpad if you want to see this script working)

Tell me theres an easier way to this :P

#include <WinAPI.au3>
#include <Misc.au3>
#include <GUIConstantsEx.au3>


$bingo="not within limits"
$labeltext =" "
$hwnd = GUICreate("Hello World", 200, 200)
GUICtrlCreateLabel($labeltext, 0, 0, 200, 150)
GUICtrlCreateLabel($bingo, 0, 150, 200, 50)


$wordpadwindow = WinGetHandle("Document -")
GUISwitch($hwnd)
GUISetState(@SW_SHOW)

While 1
;get position of fontsize control on wordpad
    $wordpadDetails = ControlGetPos ( "Document -", "","ComboBox2"  )
 

    
;get mouse coordinates relative to window $hwnd
$tPoint = _WinAPI_GetMousePos()
$tPoint2 = _WinAPI_GetMousePos(True, $wordpadwindow)
$mousex = DllStructGetData($tPoint2, "X")
$mousey = DllStructGetData($tPoint2, "Y")

$labeltext="X = " & DllStructGetData($tPoint, "X") & @LF & "Y = " & DllStructGetData($tPoint, "Y") _
& @LF & @LF & "Client" & @LF & "X = " _
& DllStructGetData($tPoint2, "X") & @LF & "Y = " & DllStructGetData($tPoint2, "Y") _
& @LF & @LF & _ 
"wordpad control x = " & $wordpadDetails[0] & @LF & _
"wordpad control y = " & $wordpadDetails[1]  & @LF & _
"wordpad control width = " & $wordpadDetails[2]  & @LF & _
"wordpad control height = " & $wordpadDetails[3] 

;Coordinates where mouse is within coordinates of control:
;upperlimits = actual x position and y position of control
$upperxlimit = $wordpadDetails[0]
$upperylimit = $wordpadDetails[1]
;lowerlimits = x position and y postion + width and height of control
$lowerxlimit = $upperxlimit + $wordpadDetails[2]
$lowerylimit = $upperylimit + $wordpadDetails[3]

;test if mouse is within x and y limits
IF $mousex > $upperxlimit AND $mousex < $lowerxlimit AND _
    $mousey > $upperylimit AND $mousey < $lowerylimit Then 
ControlSetText("Hello World", "", "Static2", "tada")
$tada = "yes"
Else
    ControlSetText("Hello World", "", "Static2", "not within limits")
    $tada = "no"
EndIf




;update the label with mouse position
ControlSetText("Hello World", "", "Static1",$labeltext)

;;;;;;;;;;;; unimportant
  $msg = GUIGetMsg(1)
  Select


    Case $msg[0] = $GUI_EVENT_CLOSE And $msg[1] = $hwnd 

      ExitLoop
  EndSelect
WEnd

if I integrate my script from my previous post about using ctrl-click ( http://www.autoitscript.com/forum/index.ph...&pid=596055 ) and chuck in a few if statements(to check if the window is the active window/visible and the control is visible) hopefully it will detect whether i've clicked a specific control using ctrl-click.

Link to comment
Share on other sites

u can make a child of your window, make a button over the button u are waiting the mouse click, then do what ever u want... this is an example made by FreeFry:

#include <WindowsConstants.au3>

Dim Const $swClass = "[CLASS:Notepad]"

If Not WinExists($swClass) Then Run("notepad.exe")

WinWait($swClass)

Dim $iwHandle = WinGetHandle($swClass)
Dim $icHandle = ControlGetHandle($iwHandle, "", "Edit1")
Dim $acPosition = ControlGetPos($iwHandle, "", $icHandle)

GUICreate("", $acPosition[2], $acPosition[3], $acPosition[0], $acPosition[1], $WS_CHILD, -1, $iwHandle)

Dim $ibID = GUICtrlCreateButton("SuperButton", 0, 0, $acPosition[2], $acPosition[3])

ControlHide($iwHandle, "", $icHandle)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $ibID
            MsgBox(0, "Button", "You clicked the all mighty super buttan wink.gif")
            WinClose($iwHandle)
            Exit
    EndSwitch
    If Not WinExists($iwHandle) Then Exit
WEnd
Edited by oMBra
Link to comment
Share on other sites

u can make a child of your window, make a button over the button u are waiting the mouse click, then do what ever u want... this is an example made by FreeFry:

That would be ok except the button serves only as a place holder and blocks any user interaction with the real control. ie in that script you can nolonger view any typing in notepad.

However your script is alot cleaner when it comes to sizing up the location and dimensions of the control.

What is the advantage of using DIM.

I've read it in the help file but I still don't get why its useful.

Link to comment
Share on other sites

when the user click on the button u made, then u can send a controlclick on the real button....

I made an example for u:

#include <WindowsConstants.au3>

Dim Const $swClass = "[CLASS:SciCalc]"

If Not WinExists($swClass) Then Run("calc.exe")

WinWait($swClass)

Dim $iwHandle = WinGetHandle($swClass)
Dim $icHandle = ControlGetHandle($iwHandle, "", 131)
Dim $acPosition = ControlGetPos($iwHandle, "", $icHandle)

GUICreate("", $acPosition[2], $acPosition[3], $acPosition[0], $acPosition[1], $WS_CHILD, -1, $iwHandle)

Dim $ibID = GUICtrlCreateButton("7", 0, 0, $acPosition[2], $acPosition[3])

ControlHide($iwHandle, "", $icHandle)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $ibID
            ControlClick($swClass, '', 131, 'Left')
            MsgBox(0, "Button", "You clicked the button")
    EndSwitch
    If Not WinExists($iwHandle) Then Exit
WEnd
Edited by oMBra
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...