暂停脚本时,AutohotKey 工具提示永久附加到光标。然而,一旦unpaused 必须更改为UNPAUSED 剩余2 秒

AutohotKey Tooltip attached to cursor permanently when PAUSED the script. Yet, once unpaused must change to UNPAUSED remaining for 2 seconds

我已经尝试了很多我在这里找到的选项,但 none 完全符合我的需要。

我编写了这个脚本来自动执行我对不同文档执行的一系列流程。

它工作得很好,虽然当我发现那些文档中有错误时我经常停止它,但我也忘记了我是否让它暂停或者我是否重新加载它甚至关闭它。

出于这个原因,我想应用一个工具提示 PAUSED,附在光标上,以便在我暂停它时永久地告诉我它不会消失,直到我删除暂停。然而,一旦我取消暂停脚本,我希望工具提示说 UNPAUSED 只剩下 2 或 3 秒。

再次:

我已经尝试了很多我在这里找到的选项,但 none 完全符合我的需要。


#NoEnv
#Warn
#Persistent

SendMode Input
SetWorkingDir %A_ScriptDir%

RandomSleep(x,y) {
Random, sleeprandom, %x%, %y%
Sleep %sleeprandom%
}

;——————————————————————————————————————————————————————————————————————————————————



;   ————————    starts  1st |       3 sets of automated clicks  ———————— · ————————
|::

; Registers original cursor position.
MouseGetPos, StartX, StartY
RandomSleep(1000,1500)
;
Loop, 3
{
    MouseClick, left
    RandomSleep(600,1000)
    ;   ;   ;   ;
    MouseClick, left
    RandomSleep(600,1000)
;
    MouseMove, 0, 70, 100, R
    RandomSleep(600,1000)
;
    MouseClick, left
    RandomSleep(600,1000)
    ;   ;   ;   ;
    MouseClick, left
    RandomSleep(600,1000)
;
    MouseMove, 0, -350, 100, R
    RandomSleep(600,1000)
}
; Moves cursor back to its original position.
MouseMove, StartX, StartY
RandomSleep(50,150)

; Registers original cursor position.
MouseGetPos, StartX, StartY
RandomSleep(50,150)
;
MouseMove, 1912, 110
RandomSleep(50,150)
;
Loop, 21
{
    MouseClick, left
    Sleep, 50
}
;
; Moves cursor back to its original position.
MouseMove, StartX, StartY
RandomSleep(50,150)

MouseMove, 1912, 110
RandomSleep(1000,1500)
;
; Moves cursor back to its original position.
MouseMove, StartX, StartY
RandomSleep(50,150)

MouseMove, 0, -3, 100, R
RandomSleep(50,150)
 Return
;   ————————    ends 1st    |       3 sets of automated clicks  ———————— · ————————


;   ————————    starts  2nd 1       5 of 10 automated clicks    ———————— · ————————
1::
; Registers original cursor position.
MouseGetPos, StartX, StartY
Sleep, 50
;
RandomSleep(500,1600)
;
Loop, 5
{
    MouseClick, left
    RandomSleep(600,1000)
    ;
    MouseClick, left
    RandomSleep(600,1000)
    ;
    MouseMove, 0, -140, 100, R
    RandomSleep(600,1000)
}
MouseMove, 0, 770, 100, R
RandomSleep(500,1600)

Loop, 5
{
    MouseClick, left
    RandomSleep(600,1000)
    ;
    MouseClick, left
    RandomSleep(600,1000)
    ;
    MouseMove, 0, -140, 100, R
    RandomSleep(600,1000)
}

Sleep, 50

Loop, 21
{
    MouseMove, 1912, 110
    Sleep, 50
    ;
    MouseClick, left
    Sleep, 50
}

Sleep, 50

Loop, 3
{
    MouseMove, 1912, 1068
    Sleep, 50
    ;
    MouseClick, left
    Sleep, 50
}
; Moves cursor back to its original position.
MouseMove, StartX, StartY
Sleep, 50

; Mueve el mouse 18 píxeles hacia abajo:
MouseMove, 0, 18, 100, R
Sleep, 50
 Return
;   ————————    ends 2nd    1       5 of 10 automated clicks    ———————— · ————————


;   ————————    starts  3th Tab     Moves page 3 clicks up      ———————— · ————————
Tab::
; Registers original cursor position.
MouseGetPos, StartX, StartY
Sleep, 50
;
Loop, 1
{
    MouseMove, 1912, 1068
    Sleep, 50
    ;
    MouseClick, left
    Sleep, 50
}
;
; Moves cursor back to its original position.
MouseMove, StartX, StartY
Sleep, 50
 Return
;   ————————    ends 3th    Tab     Moves page 3 clicks up      ———————— · ————————


;   ————————    starts  4th Q       Moves page 22 clicks down   ———————— · ————————
q::
; Registers original cursor position.
MouseGetPos, StartX, StartY
Sleep, 50
;
Loop, 21
{
    MouseMove, 1912, 110
    Sleep, 50
    ;
    MouseClick, left
    Sleep, 50
}
;
; Moves cursor back to its original position.
MouseMove, StartX, StartY
Sleep, 50
;
 Return
;   ————————    ends 4th    Q       Moves page 22 clicks down   ———————— · ————————


;   ————————    starts  5th CapsLock    Moves page 2 clicks down    ———————— · ————————
CapsLock::
; Registers original cursor position.
MouseGetPos, StartX, StartY
Sleep, 50
;
Loop, 1
{
    MouseMove, 1912, 110
    Sleep, 50
    ;
    MouseClick, left
    Sleep, 50
}
;
; Moves cursor back to its original position.
MouseMove, StartX, StartY
Sleep, 50
;
 Return
;   ————————    ends 5th    CapsLock    Moves page 2 clicks down    ———————— · ————————


;   ————————    starts  6th A       Moves page 8 clicks down    ———————— · ————————
a::
; Registers original cursor position.
MouseGetPos, StartX, StartY
Sleep, 50
;
Loop, 7
{
    MouseMove, 1912, 110
    Sleep, 50
    ;
    MouseClick, left
    Sleep, 50
}
;
; Moves cursor back to its original position.
MouseMove, StartX, StartY
Sleep, 50
;
 Return
;   ————————    ends 6th    A       Moves page 8 clicks down    ———————— · ————————


;   ————————    starts  7th W       1 set of automated clicks   ———————— · ————————
w::
RandomSleep(900,1900)
;
MouseClick, left
RandomSleep(1400,1900)
;
MouseClick, left
RandomSleep(650,1400)
;
MouseMove, 0, 70, 100, R
RandomSleep(650,1400)
;
MouseClick, left
RandomSleep(900,1400)
;
MouseClick, left
RandomSleep(400,900)
;
MouseMove, 0, -71, 100, R
RandomSleep(400,900)
;
; Registers original cursor position.
MouseGetPos, StartX, StartY
RandomSleep(100,250)
;
Loop, 7
{
    MouseMove, 1912, 110
    RandomSleep(100,250)
    ;
    MouseClick, left
    RandomSleep(100,250)
}
;
; Moves cursor back to its original position.
MouseMove, StartX, StartY
RandomSleep(100,250)
 Return
;   ————————    ends 7th    W       1 set of automated clicks   ———————— · ————————



F5::Reload

Ctrl::Pause 

如前所述: 要将工具提示永久附加到光标,您需要一个计时器或一个循环。 但是,只要脚本暂停 timers/loops 就不会 运行.

我看到的唯一解决方案是

  • 一个工具提示,例如在屏幕顶部:
  • 消息框
  • 或第二个脚本向此脚本发送暂停命令并将工具提示附加到光标。

最佳解决方案:

脚本暂停时在屏幕左上角附加工具提示:

; Use the OperateOnUnderlyingThread of the Pause command:

Ctrl::
If (A_IsPaused)
{
    Pause, , 1  
    Tooltip UNPAUSED
    Sleep, 3000
    Tooltip
}
else
{
    Pause, , 1
    CoordMode, Tooltip, Screen  
    Tooltip PAUSED, 0, 0
}
return

https://www.autohotkey.com/docs/commands/Pause.htm#Parameters

编辑

使用第二个脚本将工具提示附加到光标:

Ctrl::
DetectHiddenWindows, On
If (A_IsPaused)
{
    WinClose, %A_Temp%\Tooltip.ahk
    Pause, , 1
    FileDelete %A_Temp%\*.ahk
    FileAppend,
    (
    #NoTrayIcon
    Loop 30
    {
        Sleep, 100
        Tooltip UNPAUSED
    }
    ExitApp
    ), %A_Temp%\Tooltip.ahk
    Run %A_Temp%\Tooltip.ahk        
}
else
{
    WinClose, %A_Temp%\Tooltip.ahk
    Pause, , 1
    FileDelete %A_Temp%\*.ahk
    FileAppend,
    (
    #NoTrayIcon
    DetectHiddenWindows, On
    SetTitleMatchMode, 2
    Loop
    {
        If !WinExist("ScriptName.ahk ahk_class AutoHotkey")
            ExitApp
        Tooltip PAUSED  
        If GetKeyState("Ctrl")
            ExitApp
    }
    ), %A_Temp%\Tooltip.ahk
    Run %A_Temp%\Tooltip.ahk
}
return

用脚本名称替换“ScriptName”

EDIT2

整个脚本:

#NoEnv
#SingleInstance Force
#Warn
#UseHook

SendMode Input
SetWorkingDir %A_ScriptDir%

FileDelete %A_Temp%\*.ahk

RandomSleep(x,y) {
Random, sleeprandom, %x%, %y%
Sleep %sleeprandom%
}
;——————————————————————————————————————————————————————————————————————————————————

;   ————————    starts  1st |       3 sets of automated clicks  ———————— · ————————
|::

; Registers original cursor position.
MouseGetPos, StartX, StartY
RandomSleep(1000,1500)
;
Loop, 3
{
    MouseClick, left
    RandomSleep(600,1000)
    ;   ;   ;   ;
    MouseClick, left
    RandomSleep(600,1000)
;
    MouseMove, 0, 70, 100, R
    RandomSleep(600,1000)
;
    MouseClick, left
    RandomSleep(600,1000)
    ;   ;   ;   ;
    MouseClick, left
    RandomSleep(600,1000)
;
    MouseMove, 0, -350, 100, R
    RandomSleep(600,1000)
}
; Moves cursor back to its original position.
MouseMove, StartX, StartY
RandomSleep(50,150)

; Registers original cursor position.
MouseGetPos, StartX, StartY
RandomSleep(50,150)
;
MouseMove, 1912, 110
RandomSleep(50,150)
;
Loop, 21
{
    MouseClick, left
    Sleep, 50
}
;
; Moves cursor back to its original position.
MouseMove, StartX, StartY
RandomSleep(50,150)

MouseMove, 1912, 110
RandomSleep(1000,1500)
;
; Moves cursor back to its original position.
MouseMove, StartX, StartY
RandomSleep(50,150)

MouseMove, 0, -3, 100, R
RandomSleep(50,150)
 Return
;   ————————    ends 1st    |       3 sets of automated clicks  ———————— · ————————

;   ————————    starts  2nd 1       5 of 10 automated clicks    ———————— · ————————
1::
; Registers original cursor position.
MouseGetPos, StartX, StartY
Sleep, 50
;
RandomSleep(500,1600)
;
Loop, 5
{
    MouseClick, left
    RandomSleep(600,1000)
    ;
    MouseClick, left
    RandomSleep(600,1000)
    ;
    MouseMove, 0, -140, 100, R
    RandomSleep(600,1000)
}
MouseMove, 0, 770, 100, R
RandomSleep(500,1600)

Loop, 5
{
    MouseClick, left
    RandomSleep(600,1000)
    ;
    MouseClick, left
    RandomSleep(600,1000)
    ;
    MouseMove, 0, -140, 100, R
    RandomSleep(600,1000)
}

Sleep, 50

Loop, 21
{
    MouseMove, 1912, 110
    Sleep, 50
    ;
    MouseClick, left
    Sleep, 50
}

Sleep, 50

Loop, 3
{
    MouseMove, 1912, 1068
    Sleep, 50
    ;
    MouseClick, left
    Sleep, 50
}
; Moves cursor back to its original position.
MouseMove, StartX, StartY
Sleep, 50

; Mueve el mouse 18 píxeles hacia abajo:
MouseMove, 0, 18, 100, R
Sleep, 50
 Return
;   ————————    ends 2nd    1       5 of 10 automated clicks    ———————— · ————————


;   ————————    starts  3th Tab     Moves page 3 clicks up      ———————— · ————————
Tab::
; Registers original cursor position.
MouseGetPos, StartX, StartY
Sleep, 50
;
Loop, 1
{
    MouseMove, 1912, 1068
    Sleep, 50
    ;
    MouseClick, left
    Sleep, 50
}
;
; Moves cursor back to its original position.
MouseMove, StartX, StartY
Sleep, 50
 Return
;   ————————    ends 3th    Tab     Moves page 3 clicks up      ———————— · ————————

;   ————————    starts  4th Q       Moves page 22 clicks down   ———————— · ————————
q::
; Registers original cursor position.
MouseGetPos, StartX, StartY
Sleep, 50
;
Loop, 21
{
    MouseMove, 1912, 110
    Sleep, 50
    ;
    MouseClick, left
    Sleep, 50
}
;
; Moves cursor back to its original position.
MouseMove, StartX, StartY
Sleep, 50
;
 Return
;   ————————    ends 4th    Q       Moves page 22 clicks down   ———————— · ————————


;   ————————    starts  5th CapsLock    Moves page 2 clicks down    ———————— · ————————
CapsLock::
; Registers original cursor position.
MouseGetPos, StartX, StartY
Sleep, 50
;
Loop, 1
{
    MouseMove, 1912, 110
    Sleep, 50
    ;
    MouseClick, left
    Sleep, 50
}
;
; Moves cursor back to its original position.
MouseMove, StartX, StartY
Sleep, 50
;
 Return
;   ————————    ends 5th    CapsLock    Moves page 2 clicks down    ———————— · ————————


;   ————————    starts  6th A       Moves page 8 clicks down    ———————— · ————————
a::
; Registers original cursor position.
MouseGetPos, StartX, StartY
Sleep, 50
;
Loop, 7
{
    MouseMove, 1912, 110
    Sleep, 50
    ;
    MouseClick, left
    Sleep, 50
}
;
; Moves cursor back to its original position.
MouseMove, StartX, StartY
Sleep, 50
;
 Return
;   ————————    ends 6th    A       Moves page 8 clicks down    ———————— · ————————


;   ————————    starts  7th W       1 set of automated clicks   ———————— · ————————
w::
RandomSleep(900,1900)
;
MouseClick, left
RandomSleep(1400,1900)
;
MouseClick, left
RandomSleep(650,1400)
;
MouseMove, 0, 70, 100, R
RandomSleep(650,1400)
;
MouseClick, left
RandomSleep(900,1400)
;
MouseClick, left
RandomSleep(400,900)
;
MouseMove, 0, -71, 100, R
RandomSleep(400,900)
;
; Registers original cursor position.
MouseGetPos, StartX, StartY
RandomSleep(100,250)
;
Loop, 7
{
    MouseMove, 1912, 110
    RandomSleep(100,250)
    ;
    MouseClick, left
    RandomSleep(100,250)
}
;
; Moves cursor back to its original position.
MouseMove, StartX, StartY
RandomSleep(100,250)
 Return
;   ————————    ends 7th    W       1 set of automated clicks   ———————— · ————————

F5::Reload

Ctrl::
DetectHiddenWindows, On
If (A_IsPaused)
{
    WinClose, %A_Temp%\Tooltip.ahk
    Pause, , 1
    FileDelete %A_Temp%\*.ahk
    FileAppend,
    (
    #NoTrayIcon
    Loop 30
    {
        Sleep, 100
        Tooltip UNPAUSED
    }
    ExitApp
    ), %A_Temp%\Tooltip.ahk
    Run %A_Temp%\Tooltip.ahk        
}
else
{
    WinClose, %A_Temp%\Tooltip.ahk
    Pause, , 1
    FileDelete %A_Temp%\*.ahk
    FileAppend,
    (
    #NoTrayIcon
    DetectHiddenWindows, On
    SetTitleMatchMode, 2
    Loop
    {
        If !WinExist("ScriptName.ahk ahk_class AutoHotkey")
            ExitApp
        Tooltip PAUSED  
        If GetKeyState("Ctrl")
            ExitApp
    }
    ), %A_Temp%\Tooltip.ahk
    Run %A_Temp%\Tooltip.ahk
}
return

将代码中的“ScriptName”替换为脚本的名称。