Autohotkey 中使用两个“键序列”脚本的一些响应问题

Autohotkey 中使用两个“键序列”脚本的一些响应问题

我在 AHK 中有两个脚本,均由“键序列”(按两次 b)和(按两次 1)触发,下面是代码

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

SetTitleMatchMode RegEx ; matchs apps windows names using RegEx



;   Delay A between key sequence triggers
ARkeySeqDelayA := 250

;   if Presets Panel is in 100%
;   Y axis top in tool presets is 122 pixels
;   Y axis gap between tool presets is 29 pixels
ARtoolPresetTopY := 125
ARtoolPresetGapY := 29
return





#If WinActive("ahk_class ArtRage 3")



b::
if Keyb_presses > 0 ; SetTimer already started, so we log the keypress instead.
{
    Keyb_presses += 1
    return
}
; Otherwise, this is the first press of a new series. Set count to 1 and start
; the timer:
Keyb_presses = 1
SetTimer, Keyb, -250 ; Wait for more presses within a 250 millisecond window.
return

Keyb:
if Keyb_presses = 1 ; The key was pressed once.
{
    BlockInput, MouseMove
    Send {b}
    sleep 80
    MouseClick, left, 195, 55
    Sleep 200
    MouseClick, left, 200, 85
    BlockInput, MouseMoveOff
}
else if Keyb_presses = 2 ; The key was pressed twice.
{
    BlockInput, MouseMove
    Send {b}
    sleep 80
    MouseClick, left, 195, 55
    Sleep 200
    MouseClick, left, 200, 110
    BlockInput, MouseMoveOff
}
; Regardless of which action above was triggered, reset the count to
; prepare for the next series of presses:
Keyb_presses = 0
return





1::
if Key1_presses > 0 ; SetTimer already started, so we log the keypress instead.
{
    Key1_presses += 1
    return
}
; Otherwise, this is the first press of a new series. Set count to 1 and start
; the timer:
Key1_presses = 1
SetTimer, Key1, -250 ; Wait for more presses within a 250 millisecond window.
return

Key1:
if Key1_presses = 1 ; The key was pressed once.
{
    BlockInput, MouseMove
    MouseClick, left, 13, ARtoolPresetTopY
    BlockInput, MouseMoveOff
}
else if Key1_presses = 2 ; The key was pressed twice.
{
    BlockInput, MouseMove
    MouseClick, left, 13, ARtoolPresetTopY + (ARtoolPresetGapY * 8)
    BlockInput, MouseMoveOff
}
; Regardless of which action above was triggered, reset the count to
; prepare for the next series of presses:
Key1_presses = 0
return

但不知何故,当我触发“1”脚本时,几秒钟后我想使用“11”脚本,除非我自己(手动)之前单击了任何地方,否则它将不起作用,似乎 AHK 之前的脚本仍在运行,需要我通过单击任何地方来结束它。

另外,当我触发“bb”脚本,然后 1 秒后我想使用“1”脚本时,它不起作用,再次似乎 AHK 仍在运行前一个脚本或其他东西,我必须自己单击一下,然后它才会运行“1”脚本。因此,我不能一个接一个地运行“bb”和“1”脚本(这是我一直做的事情,非常必要),而我自己不必在它们之间进行一些鼠标点击,我该如何避免这种情况??

经过进一步的测试,我将脚本的所有执行部分替换为

Run C:\Users\myname\Desktop\AR4 bb.exe    ; the same script done in a macro recorder
click up left

我注意到问题仍然存在,脚本区分单击和双击的方式也干扰了脚本连续运行两次。如果我按下“b”等待一秒钟,但我自己不点击鼠标,然后按“bb”(两次 b),它将执行“b”,但如果我之前自己点击过几次鼠标,它将执行“bb”。为什么会发生这种情况?

我能做什么?我可以添加一些命令来使该脚本更具响应性吗?

谢谢高级。

答案1

为了控制鼠标是否单击正确窗口中的正确位置,您可以使用以下命令:

F1::
ARtoolPresetTopY := 125
ARtoolPresetGapY := 29

Ypos := ARtoolPresetTopY + (ARtoolPresetGapY * 8)
MsgBox, %Ypos%  ; Press Enter for closing this MsgBox.

; Click, 13, %Ypos%
; or
ControlClick, x13 y%Ypos%, ahk_class ArtRage 3

MouseMove, 13, %Ypos%, 0 ; this line is only needed for getting the mouse position and the name of the control you want click:
MouseGetPos, MouseX, MouseY, WindowUnderMouse, ControlUnderMouse
WinGetTitle, title, ahk_id %WindowUnderMouse%
WinGetClass, class, ahk_id %WindowUnderMouse%

MsgBox, MouseX = %MouseX%`nMouseY = %MouseY%`n`nWinTitle = %title%`nWinClass = ahk_class %class%`n`nControlUnderMouse = %ControlUnderMouse%
return
  • 除了 Click 之外,您还可以使用控制点击(那么您就不需要BlockInput)。

  • 尝试将“b::”和“1::”替换为“$b::“ 和 ”$1::“。(键盘钩子始终优先)。

  • 也可以看看:调试脚本

相关内容