AutoHotKey 警告:此变量似乎从未被赋值

问题描述 投票:0回答:2
#SingleInstance Prompt

global WinGet, WindowList, List

; Get a list of all open windows
WinGet WindowList, List

; Loop through the list and display information about each window
Loop % WindowList %
{
     ; Get the window title and process name
     this_id := WindowList%A_Index%
     WinGetTitle Title, % "ahk_id " % this_id
     WinGet ProcessName, ProcessName, % "ahk_id " % this_id

     ; Display information
     MsgBox Window %A_Index% `nTitle  %Title%`nProcess %ProcessName%
}

给予

我做错了什么?

autohotkey
2个回答
0
投票

错误的变量声明语法。

尝试:

#SingleInstance Prompt
    
    global WindowList
    
    ; Get a list of all open windows
    WinGet WindowList, List
    
    ; Loop through the list and display information about each window
    Loop %WindowList%
    {
         ; Get the window title and process name
         this_id := WindowList%A_Index%
         WinGetTitle Title, % "ahk_id " this_id
         WinGet ProcessName, ProcessName,"ahk_id " %this_id%
    
         ; Display information
         MsgBox Window %A_Index% `nTitle  %Title%`nProcess %ProcessName%
    }

0
投票

自动热键 v1:

#Requires AutoHotkey v1.1

#SingleInstance Prompt

; Get a list of all open windows
WinGet, id, list,,, Program Manager

; Loop through the list and display information about each window
Loop, %id%
{
     ; Get the window title and process name
     this_ID := id%A_Index%
     WinGetTitle Title, ahk_id %this_ID%
     WinGet ProcessName, ProcessName, ahk_id %this_ID%
     
     ; Display information
     MsgBox Window %A_Index% `nTitle:  %Title%`nProcess:  %ProcessName%
}

https://www.autohotkey.com/docs/v1/lib/WinGet.htm

自动热键 v2:

#Requires AutoHotkey v2.0

#SingleInstance Prompt

; Get a list of all open windows
ids := WinGetList(,, "Program Manager")
for this_id in ids
{
   ; Get the window title and process name
   title := WinGetTitle(this_id)
   ProcessName := WinGetProcessName(this_id)
    
   ; Display information
   MsgBox("Window " A_Index "`nTitle: "  title "`nProcessName: "  ProcessName)
}

https://www.autohotkey.com/docs/v2/lib/WinGetList.htm

© www.soinside.com 2019 - 2024. All rights reserved.