1
votes

I need to send a click to a position on a non-active window. This window does not have any clickable controls at said coordinates.

CoordMode, Mouse, Screen
SetControlDelay -1
ControlClick, x636 y189,WindowTitle,,,, NA Pos  

Every time I run the code above, it wont click at the position I specified. It instead clicks on my current mouse position, regardless of whether or not the window is active.

3
Maybe that window is hidden? Try DetectHiddenWindows, On - wOxxOm
Tried that, same issue, it works the click, but doesnt click on the coordinate, it clicks on the mouse position, - Caio Keto

3 Answers

3
votes

Some more ideas:

Update your AHK:
https://autohotkey.com/download/ahk-install.exe

Run your script as admin:

If not A_IsAdmin ;force the script to run as admin
{
    Run *RunAs "%A_ScriptFullPath%"
    ExitApp
}

Use PostMessage instead of ControlClick:

PostClick(636,189,"WindowTitle")

PostClick(x,y,win="A") {
    lParam := x & 0xFFFF | (y & 0xFFFF) << 16
    PostMessage, 0x201, , %lParam%, , %win% ;WM_LBUTTONDOWN 
    PostMessage, 0x202, , %lParam%, ,  %win% ;WM_LBUTTONUP 
}
2
votes

Oh. If no control in the window to click at those coordinates, then ControlClick is not going to work. Use a simple MouseClick command instead. If you don't have the same x y coords each time, e.g., because the window moves, you can query the window position using WinGetPos and then pass the coords to your MouseClick as variables based on that result.

    WinGetPos, Xp, Yp, Wi, He, WindowTitle
    MouseClick, left, %Xp% + 636, %Yp% + 189
0
votes

A couple of things. CoordMode should not be used (unless for some other reason) as it doesn't impact the positioning of a ControlClick -- which is always relative to the WindowTitle window you use.

Maybe set your SetTitleMatchMode to 2 because you are not using the exact correct WindowTitle text; and in addition, if your window is like a Citrix XenApp window, you may have to deal with another criteria for identifying the target window (see WinTitle in help).

Also, you could try to identify and use the ClassNN (the classname and instance number of the control) or the name/text of the control, both of which can be determined via Window Spy.

Lastly, did you try it without the Pos at the end? That is used mainly when a control class conflicts with the x y position. You can also try it without any of the stuff after WindowTitle as ControlClick, x636 y189, WindowTitle (note the space) should work by itself if you use the correct window title or other criteria:

    SetTitleMatchMode, 2
    SetControlDelay -1
    ControlClick, x636 y189, WindowTitle,,,, NA

or

    SetTitleMatchMode, 2
    SetControlDelay -1
    ControlClick, x636 y189, WindowTitle