Log the PID of an active window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Bharadwaj7895
Posts: 1
Joined: 18 Apr 2019, 22:19

Log the PID of an active window

18 Apr 2019, 22:25

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
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: Log the PID of an active window

18 Apr 2019, 22:51

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
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 283 guests