无递归重映射

Remap without recursion

我是 AutoIt 的新手,之前(经常)使用 AutoHotkey 工作过。

这是我尝试稍微重写 AutoIt 文档中的一个脚本的尝试。我唯一改变的部分是底部(Tab 键)。

我想要实现的目标:如果当前window是记事本,那么发送Ctrl-Tab而不是Tab。否则,发送正常的 Tab.

嗯,我明白了,为什么这段代码会导致递归,但我该如何避免呢?

#include <MsgBoxConstants.au3>

; Press Esc to terminate script, Pause/Break to "pause"

Global $g_bPaused = False

HotKeySet("{PAUSE}", "HotKeyPressed")
HotKeySet("{ESC}", "HotKeyPressed")
HotKeySet("{TAB}", "HotKeyPressed")

While 1
    Sleep(100)
WEnd

Func HotKeyPressed()
    Switch @HotKeyPressed
        Case "{PAUSE}"
            $g_bPaused = Not $g_bPaused
            While $g_bPaused
                Sleep(100)
                ToolTip('Script is "Paused"', 0, 0)
            WEnd
            ToolTip("")

        Case "{ESC}"
            Exit

        Case "{TAB}"
            If WinActive("[CLASS:Notepad]") Then
                Send("^{TAB}")
            Else
                Send("{TAB}")
            EndIf

    EndSwitch
EndFunc

暂时禁用热键:

Case "{TAB}"
    HotKeySet("{TAB}")  ;Cancel (or unregister) the hotkey
    If WinActive("[CLASS:Notepad]") Then
        Send("^{TAB}")
    Else
        Send("{TAB}")
    EndIf
    HotKeySet("{TAB}", "HotKeyPressed") ;re-enable hotkey
EndSwitch