0
votes

I'm making a script for 2 differents windows, and when I click on the first window, a click in the same position in the other window occurs.

The problem is, my script make the click but the x axis on the second window is always 0... and I don't know why

Maybe you got a solution or another way to script it?

This is my script:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Recommended for catching common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

;retrouver les id de 2 fenetres
WinGet, first_id, ID, window1 
WinGet, sec_id, ID, window2

;activation des fenetres
WinActivate, ahk_id %sec_id%
WinActivate, ahk_id %first_id%

; fonction pour quitter la macro
~Esc::ExitApp 
return

;test repeter clic souris
;LeftClic
~LButton::
{
    MouseGetPos, xposi, yposi 
    ControlClick, x%xposi% y%yposi%, ahk_id %first_id%,,LEFT

    WinActivate, ahk_id %sec_id%
    ControlClick, x%xposi% y%yposi%, ahk_id %sec_id%,,LEFT

    WinActivate, ahk_id %first_id%
    MouseMove, xposi, yposi 
}
return
1

1 Answers

0
votes

First and foremost, to quote the documentation for MouseGetPos:

The retrieved coordinates are relative to the active window unless CoordMode was used to change to screen coordinates.

That means it's relative to the first window.

If these windows are not identical (in any case) the chances of this working for you are slim.

With that said, if they are identical you could change CoordMode to Screen and use WinMove to size and position the second window exactly as the first, after you activate it, and then just use the Click command.

The only other thing I can think of is looking at ControlClick's options, and you will see there is Xn and Yn, which is relative to a control. Every control is in fact a window, and sometimes an application only has one control, the main window.

Side-note: You wouldn't need curly brackets {} in your script.
They are only needed in a hotkey when you have a loop or a multi-line if / else block.