TomiBelan / mute-on-focus-lost

Mute app on focus lost (AutoHotkey script)
10 stars 1 forks source link

Volume control function #2

Open Kuuh4 opened 1 month ago

Kuuh4 commented 1 month ago

Hey! Sorry to bother. I'm trying to add a function to this script (probably via the VA) in which I can target a media playing app just like MOFL (let's say, via Win+F3) and use two other keys for it's volume_mixer volume to be adjusted. I plan to apply the same concept over the MOFL targeted app, so basically, 2 volume controls, on top of MOFL functionality.

Is that possible for me to do? If so, are there any tips of which functions should I go for?

TomiBelan commented 1 month ago

It should be possible, go for it! The main idea is to call VA_ISimpleAudioVolume_GetMasterVolume() and VA_ISimpleAudioVolume_SetMasterVolume() instead of VA_ISimpleAudioVolume_GetMute() and VA_ISimpleAudioVolume_SetMute().

Though I don't understand what exactly you want. Do you want keys that work like Win+F1, i.e. which immediately affect the current focused app? In that case, make a copy of MOFL_ToggleMute() and replace its mute logic with your own. Or do you want something like Win+F2, i.e. which will react to focus/blur events in the future? In that case, change some code in MOFL_ForegroundChangeInner().

By the way, the "level" parameter is apparently a float number between 0.0 and 1.0, according to https://learn.microsoft.com/en-us/windows/win32/api/audioclient/nf-audioclient-isimpleaudiovolume-getmastervolume and https://learn.microsoft.com/en-us/windows/win32/api/audioclient/nf-audioclient-isimpleaudiovolume-setmastervolume.

Use MOFL_Log() or MsgBox() for debugging.

Hope that helps! I didn't try any of it. ;) If you need more details or have other questions, ask away.

Kuuh4 commented 1 month ago

Oh my! It will surely help a lot. VA is an extensive library, I got easily lost trying to start my search for the correct functions.

I will start working on it sometime soon! I mainly want a volume control for my current media app at the moment (manual selection) and foreground app, but probably both selected manually, like how Win+F1 and F2 already work on MOFL, but linking these selected apps to 2 pairs of keybinds that will control their values independently. I've made some planing at this fork, it may help to clarify my concept a little.

Many thanks! I use MOFL quite a lot, as competitive shooters are >>way too loud<<, so each second I can save my ears from it helps me a lot.

TomiBelan commented 1 month ago

I understand a little better now. Your goal looks quite achievable. Good luck. I'll be here if you need any hints. :)

Some ideas to think about: . Win+F2 remembers a set of multiple apps, but in your case you might want just 1 app (so selecting a new app will unselect the old app). . If you always want the same "media app", you might not even need the win+F3 and/or win+F4 key from your plan, and just hardcode a specific .exe path in your script. Either way is possible, so it depends on what you want.

I'm really glad to hear you use my script and like it! ❤️ By the way, how did you even find it? Just curious.