Sign in to follow this  
Followers 0
Streaky77

Controlclick and coords

13 posts in this topic

Hi all :-)

I can't send a left mouse click into a control (i've tried with white board of paint, and try to draw a Dot on screen)

Opt("WinTitleMatchMode", 4)
WinWait("Sans titre - Paint","UIRibbonDockTop")
ControlClick("Sans titre - Paint","UIRibbonDockTop","Afx:d0000:81", "", "", 100, 100)

Thanks a lot

Share this post


Link to post
Share on other sites



Hi all :-)

I can't send a left mouse click into a control (i've tried with white board of paint, and try to draw a Dot on screen)

Opt("WinTitleMatchMode", 4)
WinWait("Sans titre - Paint","UIRibbonDockTop")
ControlClick("Sans titre - Paint","UIRibbonDockTop","Afx:d0000:81", "", "", 100, 100)

Thanks a lot

Try to activate the window before with winactivate, see the helpfile Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Doesn't work :graduated:

Opt("WinTitleMatchMode", 4)
WinWait("Sans titre - Paint","UIRibbonDockTop")
WinActivate("Sans titre - Paint","UIRibbonDockTop")
ControlClick("Sans titre - Paint","UIRibbonDockTop","Afx:d0000:81", "", "", 100, 100)

Share this post


Link to post
Share on other sites

you get your controlId by autoit window info ?

what's type of control ?


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Take A look at this page.

You need to specify what you are sending to identify the control. Is it a class, text, name etc.

Also you seem to be using the CLASSNN, but I'm not sure that works when the classname ends with a number.

Try something like this:

Opt("WinTitleMatchMode", 4)
Global $sAppIdentifyer = "[CLASS:MSPaintApp]" ;I think this is more consistent than the name.
Global $sControlIdentifyer = "[CLASS:Afx:00000000FF6B0000:8; INSTANCE:1]" ;my control Class seems to be different from yours
Global $hWnd = WinWait($sAppIdentifyer,"") ;use the handle once a matching window is found.
WinActivate($hWnd)
Sleep(1000)
ControlClick($hWnd,"",$sControlIdentifyer, "left", "1", 100, 100)

Edit: forgot to remane a variable consistently

Edited by Tvern

Share this post


Link to post
Share on other sites

Take A look at this page.

You need to specify what you are sending to identify the control. Is it a class, text, name etc.

Also you seem to be using the CLASSNN, but I'm not sure that works when the classname ends with a number.

Try something like this:

Opt("WinTitleMatchMode", 4)
Global $sAppIdentifyer = "[CLASS:MSPaintApp]" ;I think this is more consistent than the name.
Global $sControlIdentifyer = "[CLASS:Afx:00000000FF6B0000:8; INSTANCE:1]" ;my control Class seems to be different from yours
Global $hWnd = WinWait($sAppIdentifyer,"") ;use the handle once a matching window is found.
WinActivate($hWnd)
Sleep(1000)
ControlClick($hWnd,"",$sControlIdentifyer, "left", "1", 100, 100)

Edit: forgot to remane a variable consistently

Thanks a lot. It perfectly works (with my control identifier)

:-)

Share this post


Link to post
Share on other sites

Hum, just one question about class.

Is it possible to create an autoIt program wich contain a common "Control identifier" ? I mean, anyway the CLASS:Afx014 or CLASS:Afx024, the program will work.

maybe a method exist to get the control CLASS :/

Share this post


Link to post
Share on other sites

Well you'll need something to identify the control you want to use with. A name, class, text, hidden text, instance, size, position etc.

So find out what makes your control unique. (could be a combination of all of the above.) And try to write something to identify it's unique features.

Share this post


Link to post
Share on other sites

(I'm sorry, i take the opportunity you seems to be really better than french community about control)

Really last question : Do you think it's possible to know if user has clicked in a control ?

ex, To know if user has click into the white board of paint.

thanks a lot :-)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I can think of two ways to try to do this, but I'm not quite sure how to go about it.

The first is to start monitoring for the right mouse button only when paint is the active window, then check the click coords.

There was an example that would show the control under the mouse button a while ago which should help. I'll see if I can find it again.

example (old, use the other one):

#include <Misc.au3>
Opt("WinTitleMatchMode", 4)

Global $sAppIdentifyer = "[CLASS:MSPaintApp]" ;I think this is more consistent than the name.
Global $sControlIdentifyer = "[CLASS:Afx:00000000FF6B0000:8; INSTANCE:1]" ;my control Class seems to be different from yours
Global $dll = DllOpen("user32.dll")
While 1
    WinWaitActive($sAppIdentifyer,"")
    If _IsPressed("02",$dll) Then
        ;check if the click occured on the white board based on coords.
        ;i'll try to get back on this
    EndIf
    Sleep(10)
WEnd

The other, nicer way is if you could capture the event triggered by clicking the control. I think i've seen it done before, but I'm not sure how to do it. Perhaps someone will see this and explain though.

gonna look for that other post now.

Edit: Found it

Edit2: Adjusted the WinWaitActive

#include <Misc.au3>
#include <WinAPI.au3>
Opt("WinTitleMatchMode", 4)
HotKeySet("{ESC}", "On_Exit")

Global $sAppIdentifyer = "[CLASS:MSPaintApp]"
Global $sControlClass = "Afx:00000000FF280000:8" ;don't forget to adjust!
Global $sControlIdentifyer = "[CLASS:" & $sControlClass & "; INSTANCE:1]"
Global $dll = DllOpen("user32.dll")
Global $tPoint, $hWnd
While 1
    WinWaitActive($sAppIdentifyer,"") 
    ;I found WinWaitActive() is a little slow to return, even if the window remains active, causing the script to miss clicks, if called often.
    ;This way it only gets called when the window goes inactive.
    While WinActive($sAppIdentifyer,"")
        If _IsPressed("02",$dll) Then
            $tPoint = DllStructCreate("int X;int Y")
            DllStructSetData ( $tPoint, "X", MouseGetPos(0))
            DllStructSetData ( $tPoint, "Y", MouseGetPos(1))
            $hWnd = _WinAPI_WindowFromPoint($tPoint)
            If _WinAPI_GetClassName($hWnd) = $sControlClass Then ConsoleWrite("Whiteboard right-clicked!" & @CRLF)
            While _IsPressed("02",$dll)
                Sleep(10)
            WEnd
        EndIf
        Sleep(10)
    WEnd
WEnd
Func On_Exit()
    Exit
EndFunc

As you know a better way to identify the control must be found, as the class changes. You could reverse engineer the example to check the control present on a location you know to be the whiteboard, then get it's handle and use that.

Edited by Tvern

Share this post


Link to post
Share on other sites

I make some test with the second script.

It works good but the MouseGetPos() display the "screen coords position" and not the "control coords position" :graduated:

I'm currently trying to get the control mouse coords.

thanks a lot Tvern

Share this post


Link to post
Share on other sites

Take a look at _WinAPI_GetMousePos, _WinAPI_GetMousePosX and _WinAPI_GetMousePosY. They allow you to get mouse posotions relevant to a window, or control.

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  
Followers 0