ControlClick problem

Get help with using AutoHotkey and its commands and hotkeys
Insomnia
Posts: 15
Joined: 18 May 2016, 13:11

ControlClick problem

14 Jan 2017, 08:23

Hey guys I was trying to set up autoclicker so that it will click without using my mouse pointer in certain coordinates on active window but it doesn't work(doesn't start clicking, just weird stuff)
This is my code right now(it worked with Click function instead of ControlClick)

Code: Select all

4::

loop {
	Random, num, 100, 80000
	if(num < 35000){
		Random, delay, 356, 432
	} else if(num>=35000 && num<50000){

		Random, delay, 384, 584
	} else if(num>=50000 && num<79970){

                Random, delay, 228, 304
}         else if(num>=79960 && num<79990){

                Random, delay, 120, 25104
}
          else if(num>=79990) {
                Random, delay, 46074, 105004
}

	Sleep, %delay%
	ControlClick, x726 y382, A ,,,,Pos

}
5::
Pause 
6::Reload
8::
ExitApp
guest3456
Posts: 2555
Joined: 09 Oct 2013, 10:31

Re: ControlClick problem

14 Jan 2017, 11:37

what window are you trying to use this on?

Insomnia
Posts: 15
Joined: 18 May 2016, 13:11

Re: ControlClick problem

14 Jan 2017, 15:26

What window? Should it matter? Im using it on OSBuddy
okl

Re: ControlClick problem

15 Jan 2017, 02:46

have you tried using Coordmode?

I'm only suggesting that because I dont usually use ControlClick.
Insomnia
Posts: 15
Joined: 18 May 2016, 13:11

Re: ControlClick problem

15 Jan 2017, 06:13

Didn't change anywhintg. Anyone with ideas? CoordClick feels more complicated than it is
Helgef
Posts: 3892
Joined: 17 Jul 2016, 01:02
Contact:

Re: ControlClick problem

15 Jan 2017, 06:19

Did you read Reliability?
I don't think CoordMode affects ControlClick.
Insomnia
Posts: 15
Joined: 18 May 2016, 13:11

Re: ControlClick problem

15 Jan 2017, 07:02

I added SetControlDelay, -1 and it didn't help. Also changed controlclick function to ControlClick, x724 y385, ahk_id 0x60588 also didn't help
User avatar
jeeswg
Posts: 6648
Joined: 19 Dec 2016, 01:58
Location: UK

Re: ControlClick problem

15 Jan 2017, 09:58

This link has some possible ideas regarding ControlClick:

Right controlClick on ToolbarWindow321 autohotkey - Stack Overflow
http://stackoverflow.com/questions/2715 ... autohotkey

You might want to specify the control if there is one, rather than the window for ControlClick.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
guest3456
Posts: 2555
Joined: 09 Oct 2013, 10:31

Re: ControlClick problem

15 Jan 2017, 10:15

Insomnia wrote:What window? Should it matter? Im using it on OSBuddy
yes it matters. ControlClick doesn't work on all window types. the window must respond to virtual mouse clicks for it to work.

you could try this
https://autohotkey.com/board/topic/9695 ... k-improve/

Insomnia
Posts: 15
Joined: 18 May 2016, 13:11

Re: ControlClick problem

15 Jan 2017, 11:02

guest3456 wrote:
Insomnia wrote:What window? Should it matter? Im using it on OSBuddy
yes it matters. ControlClick doesn't work on all window types. the window must respond to virtual mouse clicks for it to work.

you could try this
https://autohotkey.com/board/topic/9695 ... k-improve/
ok so here is his script that should work:

Code: Select all

ControlClick2(X, Y, WinTitle="", WinText="", ExcludeTitle="", ExcludeText="")  
{  
  hwnd:=ControlFromPoint(X, Y, WinTitle, WinText, cX, cY  
                             , ExcludeTitle, ExcludeText)  
  PostMessage, 0x200, 0, cX&0xFFFF | cY<<16,, ahk_id %hwnd% ; WM_MOUSEMOVE
  PostMessage, 0x201, 0, cX&0xFFFF | cY<<16,, ahk_id %hwnd% ; WM_LBUTTONDOWN  
  PostMessage, 0x202, 0, cX&0xFFFF | cY<<16,, ahk_id %hwnd% ; WM_LBUTTONUP  
}
Where should be my input? I'm sorry for this stupid question, but I'm new to this and don't exactly what should be left and replaced in this script, I know that I'll have to type in coordinates and hwnd somewhere but not sure if it will be in first, third or both lines
User avatar
boiler
Posts: 2615
Joined: 21 Dec 2014, 02:44

Re: ControlClick problem

15 Jan 2017, 11:33

You don't replace stuff in that script. It's a function that you include in your script, and you call with another line in your script. You would call it by giving it the x and y coordinates within the window of interest and the title of your window. It may not work, especially if your window doesn't have an addressable control, since that's what the function does. Here's how you might call it assuming the title of the window is OSBuddy:

ControlClick2(762, 382, "OSBuddy")

As others have pointed out, it may not work for your window. Just because you found some code that "works" doesn't mean it works for all windows.
guest3456
Posts: 2555
Joined: 09 Oct 2013, 10:31

Re: ControlClick problem

15 Jan 2017, 11:43

Insomnia wrote: ok so here is his script that should work:
its not that it 'should' work. it 'might' work. realize you'd also need the ControlFromPoint function as well
Insomnia wrote:Hey guys I was trying to set up autoclicker so that it will click without using my mouse pointer
why don't you want it to use your mouse pointer? you could always just move the pointer back with MouseMove after you're done doing the normal click

Insomnia
Posts: 15
Joined: 18 May 2016, 13:11

Re: ControlClick problem

15 Jan 2017, 11:58

boiler wrote:You don't replace stuff in that script. It's a function that you include in your script, and you call with another line in your script. You would call it by giving it the x and y coordinates within the window of interest and the title of your window. It may not work, especially if your window doesn't have an addressable control, since that's what the function does. Here's how you might call it assuming the title of the window is OSBuddy:

ControlClick2(762, 382, "OSBuddy")

As others have pointed out, it may not work for your window. Just because you found some code that "works" doesn't mean it works for all windows.
Yeah that's what I mean, should've worded differently. So my code looks like that right now

Code: Select all

4::
SetControlDelay, -1
loop {
	Random, num, 100, 80000
	if(num < 35000){
		Random, delay, 356, 432
	} else if(num>=35000 && num<50000){

		Random, delay, 384, 584
	} else if(num>=50000 && num<79970){

                Random, delay, 228, 304
}         else if(num>=79960 && num<79990){

                Random, delay, 120, 25104
}
          else if(num>=79990) {
                Random, delay, 46074, 105004
}

	Sleep, %delay%
	ControlClick2(762, 382, OSBuddy) 
{  
  hwnd:=ControlFromPoint(X, Y, WinTitle, WinText, cX, cY  
                             , ExcludeTitle, ExcludeText)  
  PostMessage, 0x200, 0, cX&0xFFFF | cY<<16,, ahk_id %hwnd% ; WM_MOUSEMOVE
  PostMessage, 0x201, 0, cX&0xFFFF | cY<<16,, ahk_id %hwnd% ; WM_LBUTTONDOWN  
  PostMessage, 0x202, 0, cX&0xFFFF | cY<<16,, ahk_id %hwnd% ; WM_LBUTTONUP  
}
  
}
6::
Reload
8::
ExitApp
But it says Error:call to non existent function and points to this line

Code: Select all

 hwnd:=ControlFromPoint(X, Y, WinTitle, WinText, cX, cY  
                             , ExcludeTitle, ExcludeText)  
Insomnia
Posts: 15
Joined: 18 May 2016, 13:11

Re: ControlClick problem

15 Jan 2017, 12:01

guest3456 wrote:
Insomnia wrote: ok so here is his script that should work:
its not that it 'should' work. it 'might' work. realize you'd also need the ControlFromPoint function as well
Insomnia wrote:Hey guys I was trying to set up autoclicker so that it will click without using my mouse pointer
why don't you want it to use your mouse pointer? you could always just move the pointer back with MouseMove after you're done doing the normal click
Because I want to use my computer while it autoclicks?
User avatar
boiler
Posts: 2615
Joined: 21 Dec 2014, 02:44

Re: ControlClick problem

15 Jan 2017, 12:13

As guest3456 pointed out, you need to include the function ControlFromPoint in your code. See HotKeyIt's post in this thread.
User avatar
boiler
Posts: 2615
Joined: 21 Dec 2014, 02:44

Re: ControlClick problem

15 Jan 2017, 12:16

You have incorporated the function in your code incorrectly. You need to include the whole function exactly as is in your code, then you call it. You don't replace the parameters in the function definition with your values. Quick example:

Code: Select all

Sum := Add(2, 3)
MsgBox, %Sum%
return

Add(num1, num2)
{
    return num1 + num2
}
guest3456
Posts: 2555
Joined: 09 Oct 2013, 10:31

Re: ControlClick problem

15 Jan 2017, 12:56

just do this and be done:

Code: Select all

MouseGetPos, mx, my
Click, 726, 382
MouseMove, %mx%, %my%

Insomnia
Posts: 15
Joined: 18 May 2016, 13:11

Re: ControlClick problem

15 Jan 2017, 13:29

boiler wrote:As guest3456 pointed out, you need to include the function ControlFromPoint in your code. See HotKeyIt's post in this thread.
Ok I took note of both of your posts and now my code looks like this:

Code: Select all

ControlClick2(X, Y, WinTitle="", WinText="", ExcludeTitle="", ExcludeText="")

{

  hwnd:=ControlFromPoint(X, Y, WinTitle, WinText, cX, cY

                             , ExcludeTitle, ExcludeText)

  PostMessage, 0x201, 0, cX&0xFFFF | cY<<16,, ahk_id %hwnd% ; WM_LBUTTONDOWN

  PostMessage, 0x202, 0, cX&0xFFFF | cY<<16,, ahk_id %hwnd% ; WM_LBUTTONUP

  PostMessage, 0x203, 0, cX&0xFFFF | cY<<16,, ahk_id %hwnd% ; WM_LBUTTONDBLCLCK

  PostMessage, 0x202, 0, cX&0xFFFF | cY<<16,, ahk_id %hwnd% ; WM_LBUTTONUP

}



ControlFromPoint(X, Y, WinTitle="", WinText="", ByRef cX="", ByRef cY="", ExcludeTitle="", ExcludeText="")

{

    if !(hwnd := WinExist(WinTitle, WinText, ExcludeTitle, ExcludeText))

        return false

    

    VarSetCapacity(pt,8)



    ; Convert coords -- relative to top-left of window -> relative to client area.

    VarSetCapacity(wi,60), NumPut(60,wi)

    DllCall("GetWindowInfo","uint",hwnd,"uint",&wi)

    NumPut(X + (w:=NumGet(wi,4,"int")) - (cw:=NumGet(wi,20,"int")), pt,0)

    NumPut(Y + (h:=NumGet(wi,8,"int")) - (ch:=NumGet(wi,24,"int")), pt,4)

    

    Loop {

        child := DllCall("ChildWindowFromPointEx","uint",hwnd,"int64",NumGet(pt,0,"int64"),"uint",0x5)

        if !child or child=hwnd

            break

        ; Make pt relative to child client area.

        DllCall("MapWindowPoints","uint",hwnd,"uint",child,"uint",&pt,"uint",1)

        hwnd := child

    }

    cX := NumGet(pt,0,"int")

    cY := NumGet(pt,4,"int")

    return hwnd

}
But still the same problem, it looks like something is happening with the window when I point my mouse cursor on it(nothing notable), but it doesn't click anywhere.
Insomnia
Posts: 15
Joined: 18 May 2016, 13:11

Re: ControlClick problem

15 Jan 2017, 13:48

guest3456 wrote:just do this and be done:

Code: Select all

MouseGetPos, mx, my
Click, 726, 382
MouseMove, %mx%, %my%
When it clicks 3 times per second it's kinda unusable
User avatar
boiler
Posts: 2615
Joined: 21 Dec 2014, 02:44

Re: ControlClick problem

15 Jan 2017, 14:19

Insomnia wrote:Ok I took note of both of your posts and now my code looks like this:

Code: Select all

ControlClick2(X, Y, WinTitle="", WinText="", ExcludeTitle="", ExcludeText="")

{

  hwnd:=ControlFromPoint(X, Y, WinTitle, WinText, cX, cY

                             , ExcludeTitle, ExcludeText)

  PostMessage, 0x201, 0, cX&0xFFFF | cY<<16,, ahk_id %hwnd% ; WM_LBUTTONDOWN

  PostMessage, 0x202, 0, cX&0xFFFF | cY<<16,, ahk_id %hwnd% ; WM_LBUTTONUP

  PostMessage, 0x203, 0, cX&0xFFFF | cY<<16,, ahk_id %hwnd% ; WM_LBUTTONDBLCLCK

  PostMessage, 0x202, 0, cX&0xFFFF | cY<<16,, ahk_id %hwnd% ; WM_LBUTTONUP

}



ControlFromPoint(X, Y, WinTitle="", WinText="", ByRef cX="", ByRef cY="", ExcludeTitle="", ExcludeText="")

{

    if !(hwnd := WinExist(WinTitle, WinText, ExcludeTitle, ExcludeText))

        return false

    

    VarSetCapacity(pt,8)



    ; Convert coords -- relative to top-left of window -> relative to client area.

    VarSetCapacity(wi,60), NumPut(60,wi)

    DllCall("GetWindowInfo","uint",hwnd,"uint",&wi)

    NumPut(X + (w:=NumGet(wi,4,"int")) - (cw:=NumGet(wi,20,"int")), pt,0)

    NumPut(Y + (h:=NumGet(wi,8,"int")) - (ch:=NumGet(wi,24,"int")), pt,4)

    

    Loop {

        child := DllCall("ChildWindowFromPointEx","uint",hwnd,"int64",NumGet(pt,0,"int64"),"uint",0x5)

        if !child or child=hwnd

            break

        ; Make pt relative to child client area.

        DllCall("MapWindowPoints","uint",hwnd,"uint",child,"uint",&pt,"uint",1)

        hwnd := child

    }

    cX := NumGet(pt,0,"int")

    cY := NumGet(pt,4,"int")

    return hwnd

}
But still the same problem, it looks like something is happening with the window when I point my mouse cursor on it(nothing notable), but it doesn't click anywhere.
That's your code? That's just the functions. It can't do anything. You need to call the main one with the x and y values and the window title like I showed you.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], scriptors and 172 guests