2

我认为以下代码可能有效,但没有。原因可能在于该Throw命令是在热键线程中执行的,而不是在自动执行部分线程中。

try 
{
    count := 0
    loop {
        tooltip % ++count
        sleep 200
    }
} catch {
}
msgbox done
Exitapp

Esc::ExitAPp
^1::throw

那么有没有办法知道控制流属于哪个线程呢?AutoHotkey 是否有线程 ID 或类似变量的变量?


下面的代码显示两个(伪)线程返回相同的数字。因此,如果有的话,我需要知道 AutoHotkey 中的线程 ID。我在某处读到 AutoHotkey 线程只是一个函数调用。但我期待可能有一种方法来识别伪线程。

try 
{
    count := 0
    loop {
        tooltip % ++count "`nThread ID: " DllCall("GetWindowThreadProcessId", "Int", A_ScriptHwnd, "Int", "0")
        sleep 200
    }
} catch {
}
msgbox done
Exitapp

Esc::ExitAPp
^1::
    MsgBox, % DllCall("GetWindowThreadProcessId", "Int", A_ScriptHwnd, "Int", "0")
    throw
Return
4

1 回答 1

0

这是你想要的?

^w::
WinGet, WinID,, A
ThreadID:=DllCall("GetWindowThreadProcessId", "Int", WinID, "Int", "0")
MsgBox, %ThreadID%
Return
于 2012-11-29T07:39:46.150 回答