Jump to content

Recommended Posts

Posted

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

Posted

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

Posted

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.

$oIAudioSessionControl2.GetProcessId($ProcessID)
                $oIAudioMeterInformation = ObjCreateInterface($pIAudioSessionControl2, $sIID_IAudioMeterInformation, $sTagIAudioMeterInformation)
                $oIAudioSessionControl2.AddRef
                $oIAudioMeterInformation.GetPeakValue($fPeakValue)
                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
                EndIf

 

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

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)
        EndIf
    Next
    If $sHold Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(1, 0, 0)
EndFunc
Func terminate()
    exit
EndFunc

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)

Posted

On further examination Windows Task Manager shows both PID 12724 and 5880 as beloning to microsoft edge exe file, which is strange as I only have 1 microsoft edge window open for testing purposes.

Posted (edited)

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

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...