Jump to content

Recommended Posts

Posted

Hey, im trying to learn controlclick, this is the second post i make about this as my other one got locked because I was trying to learn it using a game i made (sorry about that, didnt know it was against the rules) So I'm trying to learn it with windows paint instead.

Right now, im just trying to make a dot on the screen, but I cant get it work.

 

Anyways, here is the code I have:


         WinActivate("Namnlös - Paint")
         Opt("MouseCoordMode", 2)
         ControlClick("Namnlös - Paint" , "" , "MSPaintApp1" ,"left" , 1, 850, 198)

 

And here is a picture of the window info.

 

4fd6eb8cbaaf65d6c38c5a9c52c28d72.png

Posted (edited)

You need to use the handle of the Control (Afx:...:81) not the handle of the Wndow.  And if you try to control a game like this, you most probably have to forget it, won't work as most game doesn't have a Control to send key strokes to.

Edited by Nine
Posted
20 minutes ago, Nine said:

You need to use the handle of the Control (Afx:...:81) not the handle of the Wndow.  And if you try to control a game like this, you most probably have to forget it, won't work as most game doesn't have a Control to send key strokes to.

Like I said, im trying to use it with paint(for learning) and I already tried Afx... and that didnt work either.

Posted
1 hour ago, Nine said:

It is working for me.  Your code may be wrong.  Post your script...

ps. forgot to tell you, Afx control varies from 1 instance to the other !

Here is my full code:

 

Func StartLoop()
   MsgBox(0, "Starting", "Press ESC to stop")
   While 1


         WinActivate("Namnlös - Paint")
         Opt("MouseCoordMode", 0)
         ControlClick("Namnlös - Paint", "", "MSPaintApp1","left",1, 850, 198)
         Sleep($interval)

      Sleep(50)
   WEnd
EndFunc

Posted (edited)

You got all wrong (sorry to say).  First always use CLASS whenever possible.  It is much more reliable than title.  Second your control is totally off.  Third you do not need to set Opt as you are trying to use ControlClick and not MouseClick (which would be pertinent then).  Anyway try this :

#include <WinAPIGdiDC.au3>
#include <SendMessage.au3>
#include <WinAPISysWin.au3>
#include <Array.au3>

$hWnd = WinGetHandle("[CLASS:MSPaintApp]")
If not $hWnd Then Exit MsgBox ($MB_SYSTEMMODAL,"","Paint must be started")
;WinActivate ($hWnd)
;WinWaitActive ($hWnd)
$hCtrl = ControlGetHandle ($hWnd, "", "[REGEXPCLASS:Afx:.+:8]")

Mousedrag(200,210,400,410)
Mousedrag(400,410,600,210)
Mousedrag(600,210,400,010)
Mousedrag(400,010,200,210)

ControlClick ($hWnd, "", $hCtrl, "left", 1, 100, 100)

Func Mousedrag($x1,$y1,$x2,$y2)
    Local $WM_MOUSEMOVE     =  0x0200
    Local $MK_LBUTTON       =  0x0001
    Local $WM_LBUTTONDOWN   =  0x0201
    Local $WM_LBUTTONUP     =  0x0202

    _SendMessage($hCtrl, $WM_MOUSEMOVE, 0, _WinAPI_MakeLong($x1, $y1))
    _SendMessage($hCtrl, $WM_LBUTTONDOWN, $MK_LBUTTON, _WinAPI_MakeLong($x1, $y1))
    _SendMessage($hCtrl, $WM_MOUSEMOVE, 0, _WinAPI_MakeLong($x2, $y2))
    _SendMessage($hCtrl, $WM_LBUTTONUP, $MK_LBUTTON, _WinAPI_MakeLong($x2, $y2))
EndFunc

That will work even in background.  If you want to see it live, just uncomment the win* function.

ps. when posting code, please use this tool.

Edited by Nine
Posted
20 hours ago, Nine said:

You got all wrong (sorry to say).  First always use CLASS whenever possible.  It is much more reliable than title.  Second your control is totally off.  Third you do not need to set Opt as you are trying to use ControlClick and not MouseClick (which would be pertinent then).  Anyway try this :

#include <WinAPIGdiDC.au3>
#include <SendMessage.au3>
#include <WinAPISysWin.au3>
#include <Array.au3>

$hWnd = WinGetHandle("[CLASS:MSPaintApp]")
If not $hWnd Then Exit MsgBox ($MB_SYSTEMMODAL,"","Paint must be started")
;WinActivate ($hWnd)
;WinWaitActive ($hWnd)
$hCtrl = ControlGetHandle ($hWnd, "", "[REGEXPCLASS:Afx:.+:8]")

Mousedrag(200,210,400,410)
Mousedrag(400,410,600,210)
Mousedrag(600,210,400,010)
Mousedrag(400,010,200,210)

ControlClick ($hWnd, "", $hCtrl, "left", 1, 100, 100)

Func Mousedrag($x1,$y1,$x2,$y2)
    Local $WM_MOUSEMOVE     =  0x0200
    Local $MK_LBUTTON       =  0x0001
    Local $WM_LBUTTONDOWN   =  0x0201
    Local $WM_LBUTTONUP     =  0x0202

    _SendMessage($hCtrl, $WM_MOUSEMOVE, 0, _WinAPI_MakeLong($x1, $y1))
    _SendMessage($hCtrl, $WM_LBUTTONDOWN, $MK_LBUTTON, _WinAPI_MakeLong($x1, $y1))
    _SendMessage($hCtrl, $WM_MOUSEMOVE, 0, _WinAPI_MakeLong($x2, $y2))
    _SendMessage($hCtrl, $WM_LBUTTONUP, $MK_LBUTTON, _WinAPI_MakeLong($x2, $y2))
EndFunc

That will work even in background.  If you want to see it live, just uncomment the win* function.

ps. when posting code, please use this tool.

wow thank you! works great!

Posted
On 4/20/2020 at 11:15 PM, Nine said:

You got all wrong (sorry to say).  First always use CLASS whenever possible.  It is much more reliable than title.  Second your control is totally off.  Third you do not need to set Opt as you are trying to use ControlClick and not MouseClick (which would be pertinent then).  Anyway try this :

#include <WinAPIGdiDC.au3>
#include <SendMessage.au3>
#include <WinAPISysWin.au3>
#include <Array.au3>

$hWnd = WinGetHandle("[CLASS:MSPaintApp]")
If not $hWnd Then Exit MsgBox ($MB_SYSTEMMODAL,"","Paint must be started")
;WinActivate ($hWnd)
;WinWaitActive ($hWnd)
$hCtrl = ControlGetHandle ($hWnd, "", "[REGEXPCLASS:Afx:.+:8]")

Mousedrag(200,210,400,410)
Mousedrag(400,410,600,210)
Mousedrag(600,210,400,010)
Mousedrag(400,010,200,210)

ControlClick ($hWnd, "", $hCtrl, "left", 1, 100, 100)

Func Mousedrag($x1,$y1,$x2,$y2)
    Local $WM_MOUSEMOVE     =  0x0200
    Local $MK_LBUTTON       =  0x0001
    Local $WM_LBUTTONDOWN   =  0x0201
    Local $WM_LBUTTONUP     =  0x0202

    _SendMessage($hCtrl, $WM_MOUSEMOVE, 0, _WinAPI_MakeLong($x1, $y1))
    _SendMessage($hCtrl, $WM_LBUTTONDOWN, $MK_LBUTTON, _WinAPI_MakeLong($x1, $y1))
    _SendMessage($hCtrl, $WM_MOUSEMOVE, 0, _WinAPI_MakeLong($x2, $y2))
    _SendMessage($hCtrl, $WM_LBUTTONUP, $MK_LBUTTON, _WinAPI_MakeLong($x2, $y2))
EndFunc

That will work even in background.  If you want to see it live, just uncomment the win* function.

ps. when posting code, please use this tool.

Hey! Im trying to use this with google chrome, to make it open and close tabs, right now I have it like this:

 

#include <WinAPIGdiDC.au3>
#include <SendMessage.au3>
#include <WinAPISysWin.au3>
#include <Array.au3>

$hWnd = WinGetHandle("[CLASS:Chrome_WidgetWin_1]")
If not $hWnd Then Exit MsgBox ($MB_SYSTEMMODAL,"","Paint must be started")
;WinActivate ($hWnd)
;WinWaitActive ($hWnd)
$hCtrl = ControlGetHandle ($hWnd, "", "[REGEXPCLASS:Intermediate D3D Window1]")



ControlClick ($hWnd, "", $hCtrl, "left", 1, 100, 100)


ControlClick ($hWnd, "", $hCtrl, "left", 1, 473, 24)

I suppose I got the Class name wrong?

e0c7d48640d152f55547463cd6ade0e8.png

Posted

Did you take a look at WebDriver ?  Not sure how it would work with autopy, you can ask in thread.

As for you question, do not use REGEXPCLASS if the control is static.  In Paint every instance has a different class, that is why I used  RegExp.  But in your case, it definitely looks static, so just use it as is.  Also check the content of $hCtrl to make sure you got a working handle.

Again, take a timeout to look at WebDriver, cause sooner or later you will hit a wall and you will be forced to use the UDF (or UIAutomation UDF)

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...