简体   繁体   English

使用自动热键进行鼠标控制

[英]Mouse Control with autohotkey

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. 我正在为2个不同的窗口制作脚本,当我单击第一个窗口时,在另一个窗口中的相同位置会发生单击。

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 问题是,我的脚本进行了单击,但是第二个窗口上的x轴始终为0 ...,但我不知道为什么

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

First and foremost, to quote the documentation for MouseGetPos : 首先,要引用MouseGetPos的文档:

The retrieved coordinates are relative to the active window unless CoordMode was used to change to screen coordinates. 除非使用CoordMode更改为屏幕坐标,否则检索到的坐标是相对于活动窗口的。

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. 话虽如此,如果它们相同,则可以将CoordMode更改为Screen,然后使用WinMove来将第二个窗口的大小和位置与第一个窗口完全相同,然后将其激活,然后使用Click命令。

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. 我能想到的唯一另一件事是查看ControlClick的选项,您将看到Xn和Yn,它们相对于控件。 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 . 仅当您有循环或多行if / else block时,才需要在热键中使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM