Jump to content

How to detect which window made any sound?


Recommended Posts

Hi all,


Is there a script/command that enables autoit to detect which window made a sound? (any sound)

I am interested for example when browser window with email, receives new email -> makes its normal sound -> autoit WinActive that window

browser window with timer running ->makes beep when timer ends ->autoit winactive that window so I can reset timer

Thank you

Link to comment
Share on other sites

There is a pretty good example in that thread :


It will give you the process.  If the window is required, then you will need to look for it based on the PID, but I believe process should be enough.

Link to comment
Share on other sites

Thank you for your reply, however using the above code to get the process does not seem to be enough for my purpose..

for example it returns "chrome.exe" , but I am usually running other chrome windows, I wonder if there is a way to get the specific window please

Link to comment
Share on other sites

Link to comment
Share on other sites

thank you once again.

I have spent the last 2 hours 😅 trying to edit the above script so that it returns or consolewrite the PID, however I seem to be getting either 0 or an incorrect number (not the actual PID of the window).  The following seems to be the relevant snippet of code from the code you linked above.

                $oIAudioMeterInformation = ObjCreateInterface($pIAudioSessionControl2, $sIID_IAudioMeterInformation, $sTagIAudioMeterInformation)
                If $fPeakValue > 0 Then
                    ReDim $aApp[UBound($aApp) + 1][2]                    
                    $aApp[UBound($aApp) - 1][0] = _ProcessGetName($ProcessID)
                    ConsoleWrite($ProcessID) ; --------------------------------------------------- I added this line which is returning wrong PID
                    $aApp[UBound($aApp) - 1][1] = $fPeakValue


Link to comment
Share on other sites

How do you know it is the wrong PID (which is not the handle of the window BTW).  How did you check if it is the right PID.  Show the code you are using to make such an assumption.

Link to comment
Share on other sites

$i = WinGetProcess("Youtube - Microsoft Edge")

I first used this script(1)^ to get the PID, and confirmed PID with following script(2):

$wintitleProcess = _WinGetByPID(12724)
MsgBox(0,"my Name",$wintitleProcess)

;Smoke_N's WinGetByPID
Func _WinGetByPID($iPID, $nArray = 1);0 will return 1 base array; leaving it 1 will return the first visible window it finds
    If IsString($iPID) Then $iPID = ProcessExists($iPID)
    Local $aWList = WinList(), $sHold
    For $iCC = 1 To $aWList[0][0]
        If WinGetProcess($aWList[$iCC][1]) = $iPID And _
            BitAND(WinGetState($aWList[$iCC][1]), 2) Then
            If $nArray Then Return $aWList[$iCC][0]
            $sHold &= $aWList[$iCC][0] & Chr(1)
    If $sHold Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(1, 0, 0)
Func terminate()

Script (2) shows that particular window as being PID 12724, while the sound detection script returns PID as 5880. 

When I input 5880 into script(2), the MsgBox returns 0.  When I input 12724 into script (2), the MsgBox returns "Youtube - Microsoft Edge" (correctly)

Link to comment
Share on other sites

Remember most processes create child process we do not know about.  You may need to search for parent process.  But I think you should reverse the logic, once you got a PID, search for the handle related to that PID.  WinList and WinGetProcess can give you that information.

Just noticed your previous post.  So you know about Win* functions.

Edited by Nine
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...