;PID-or-Name 参数为空, 则获取脚本自身的 PID
Process, Exist
NewPID = %ErrorLevel% 
MsgBox A matching process has appeared (Process ID is %NewPID%).

a_scriptPID := DllCall("GetCurrentProcessId")	; get script's PID
MsgBox %a_scriptPID%


应用于调试环境的设置,设置Dbgview只捕捉当前脚本PID

;启动Dbgview

if !WinExist("ahk_class dbgviewClass") 
{
		Run, E:\快盘\AHK\Dbgview.exe,, UseErrorLevel, PID
		WinWaitActive, ahk_pid %PID%, ,2
	} else 
	{
		WinRestore, ahk_class dbgviewClass
		Process, wait, dbgview.exe, 5.5
		PID = %ErrorLevel%  ; 由于 ErrorLevel 会经常发生改变, 所以要立即保存这个值.
		if PID = 0
		{
			MsgBox The specified process did not appear within 5.5 seconds.
			return
		}
	}

;清除Dbgview过历史记录,等同发送^x
WinMenuSelectItem,ahk_class dbgviewClass,,Edit, Clear Display, 

;设置Dbgview过滤进程
a_scriptPID := DllCall("GetCurrentProcessId")	; get script's PID
WinMenuSelectItem,ahk_class dbgviewClass,,Edit, Filter/Highlight..., ;	
winwait, DebugView Filter
winactivate, DebugView Filter
Winwaitactive, DebugView Filter 
MouseGetPos, x,y
mouseclick, left, 125, 85,,0
MouseMove, x,y,0
send, [%a_scriptPID%*{Enter}
send, !M{Down}{Enter}
;输出调试内容
s:="HelloWorld"
OutputDebug %s%