Hi, I am new to Autohotkey. I want to log the PID of active window whenever I do switch between processes using ALT+TAB or mouse click. For instance, each time I switch between notepad and mozilla firefox I want to log the PID of active window in excel or notepad or wherever. Is there any way to achieve it?
Edit: Topic subject line added ~ gregster
Log the PID of an active window
-
- Posts: 1
- Joined: 18 Apr 2019, 22:19
Re: Log the PID of an active window
It sounds like you need a loop that waits until the current window is no longer active. This quick example should get you started:
Code: Select all
Loop
{
WinGetActiveTitle, ActiveWindow ; Store the currently active window's title in ActiveWindow
WinGet, ActiveWinPID, PID, %ActiveWindow% ; Get the PID for the currently active window
FileAppend, %ActiveWinPID%=%ActiveWindow%`n, log.txt ; Write the PID to a log file
WinWaitNotActive, %ActiveWindow% ; Wait for the window to no longer be active
}
Who is online
Users browsing this forum: Google [Bot] and 283 guests