hey guys,
Can anyone tell me if it is possible to use alert sounds from windows to trigger my AUTOHOTKEY script ?
I mean, every time windows plays that a sound alert Would start a previously programmed command sequence
Thank you in advance
Cheers
Autohotkey script Triggered by sound alert on windows?
Re: Autohotkey script Triggered by sound alert on windows?
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Persistent
#Include *i <Acc>
OnAlertSound(hWinEventHook, event, hWnd, idObject, idChild, dwEventThread, dwmsEventTime) {
Critical
MsgBox % ((ofe := Func("Acc_ObjectFromEvent"))) ? ofe.call(_idChild_, hWnd, idObject, idChild).accName : "If you had the Acc library in a standard AHK library folder, you would be seeing the name of the program event here instead"
Critical Off
}
AtExit()
{
global hWinEventHook, lpfnWinEventProc
if (hWinEventHook)
DllCall("UnhookWinEvent", "Ptr", hWinEventHook), hWinEventHook := 0
if (lpfnWinEventProc)
DllCall("GlobalFree", "Ptr", lpfnWinEventProc, "Ptr"), lpfnWinEventProc := 0
return 0
}
OnExit("AtExit")
hWinEventHook := DllCall("SetWinEventHook", "UInt", EVENT_SYSTEM_SOUND := 0x0001, "UInt", EVENT_SYSTEM_SOUND, "Ptr", 0, "Ptr", (lpfnWinEventProc := RegisterCallback("OnAlertSound", "")), "UInt", 0, "UInt", 0, "UInt", WINEVENT_OUTOFCONTEXT := 0x0000 | WINEVENT_SKIPOWNPROCESS := 0x0002)
EDIT: By "sound alert", I assume you mean the standard Windows sounds played when something happens (like Chrome annoyingly calling Beep() when it can't find something on the page). If you mean being notified when an application plays any arbitrary sound, good luck with that. You might be able to rig something up with the Core Audio API to watch the meter for a specific application, but I'm not interested in finding out how to do that
Re: Autohotkey script Triggered by sound alert on windows?
thanks man.
and yes, it would be a pre-defined sound, i can setup anyone I want to
the application is a stock scanner (trade ideas) and it plays a sound alert whenever it finds a stock respecting the filters of my trading strategy
i thought something like that, the audio meter on microsoft windows main taskbar. if is silence = do nothing, if it plays any sound = triggers my autohotkey script
and yes, it would be a pre-defined sound, i can setup anyone I want to
the application is a stock scanner (trade ideas) and it plays a sound alert whenever it finds a stock respecting the filters of my trading strategy
i thought something like that, the audio meter on microsoft windows main taskbar. if is silence = do nothing, if it plays any sound = triggers my autohotkey script