thqby / ahk2_lib

MIT License
222 stars 31 forks source link

[Audio.ahk] How to use IAudioEndpointVolume ControlChangeNotify #63

Closed cococow123 closed 3 weeks ago

cococow123 commented 3 weeks ago

Hi,

I'm trying to make a script to monitor audio level & mute changes on an audio device. So far I'm able to get the exact device and information from the endpointvolume.h header.

This does work: Device.Activate(IAudioEndpointVolume).GetMasterVolumeLevelScalar()

However, I can't seem to understand how the RegisterControlChangeNotify function should be setup to receive the events. I've tried passing in a function for a callback but got errors: Error: This value of type "Func" has no property named "Ptr".

Upon looking at the Audio.ahk code, it seems the IAudioEndpointVolumeCallback interface is not implemented.

Am I missing something?

thqby commented 3 weeks ago

The interfaces related to notification are implemented in the latest version.

aev := IMMDeviceEnumerator().GetDefaultAudioEndpoint().Activate(IAudioEndpointVolume)
cb := IAudioEndpointVolumeCallback()
cb.OnNotify := (this, notify) => OutputDebug(notify.fMasterVolume '`n')
aev.RegisterControlChangeNotify(cb)
Persistent