CommZ3 0 Posted January 17 Share Posted January 17 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 post Share on other sites
Nine 1,515 Posted January 17 Share Posted January 17 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. Xandy 1 Not much of a signature but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search content in au3 files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector GIF Animation (cached) Screen Scraping Link to post Share on other sites
CommZ3 0 Posted January 17 Author Share Posted January 17 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 post Share on other sites
Nine 1,515 Posted January 17 Share Posted January 17 Yes of course there is a way to identify the actual window. Search the forum about "find window from PID", you should easily find multiple examples of it. Xandy 1 Not much of a signature but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search content in au3 files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector GIF Animation (cached) Screen Scraping Link to post Share on other sites
CommZ3 0 Posted January 18 Author Share Posted January 18 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 Link to post Share on other sites
Nine 1,515 Posted January 18 Share Posted January 18 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. Not much of a signature but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search content in au3 files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector GIF Animation (cached) Screen Scraping Link to post Share on other sites
CommZ3 0 Posted January 18 Author Share Posted January 18 $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) Link to post Share on other sites
CommZ3 0 Posted January 18 Author Share Posted January 18 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. Link to post Share on other sites
Nine 1,515 Posted January 18 Share Posted January 18 (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 January 18 by Nine Not much of a signature but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search content in au3 files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector GIF Animation (cached) Screen Scraping Link to post Share on other sites
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now