Mute audio when bluetooth headphones disconnect

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
akirofe
Posts: 149
Joined: 05 Apr 2021, 21:54

Mute audio when bluetooth headphones disconnect

Post by akirofe » 30 Jun 2022, 19:44

Hi guys,

I listen to online radio at work with my bluetooth headphones. When I go to toilet I don't remember to take my headphones off and the headphones' bluetooth disconnects with the computer and the radio switches to play on the computer's built-in speakers.

Could you please help me with a code to mute or stop the audio when bluetooth headphones disconnect?

Thank you very much guys!!
*** Thank you for reading. I am not in coding and know almost nothing about professional coding, hope for your patience and deeply appreciate any of your kind helps. My current interest in this awesome AHK is due to that my work is graphical ((architect/CAD) and, to reduce strains, my right hand is better off not leaving the mouse (an MMO mouse that has 12 side keys which I maps a lot of F keys and other keys in) as much as possible. All the best you lovely coders! ***

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Mute audio when bluetooth headphones disconnect

Post by BoBo » 01 Jul 2022, 02:17

You could use SetTimer, periodically checking for your BT device. Maybe this helps: viewtopic.php?p=411138#p411138 (that has been created by @malcev) :)

Old, but seems to be able detecting a change via the registry!? https://www.autohotkey.com/board/topic/70836-any-way-to-detect-bluetooth-device-status/ :think:

RussF
Posts: 1240
Joined: 05 Aug 2021, 06:36

Re: Mute audio when bluetooth headphones disconnect

Post by RussF » 01 Jul 2022, 06:09

Are you running Windows 10? I don't have Win 11, so I can't be certain it behaves the same, but would assume it does.

My Win 10 maintains separate volume levels for each output device attached (speakers, headphones, bluetooth, etc.) You can verify this by clicking on the speaker icon in your system tray with your headphones disconnected to see the value, then connect them and see the difference.
image.png
image.png (37.96 KiB) Viewed 1278 times
image.png
image.png (38.09 KiB) Viewed 1278 times
Simply disconnect your headphones, play the radio app and adjust the volume of the speakers to at or near zero (at least to a level that won't bother your co-workers). Then, connect the headset and adjust the volume to your preference. There shouldn't be a need for any scripting - at least I don't need any on my system at work for the same reason.

Russ



malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Mute audio when bluetooth headphones disconnect

Post by malcev » 02 Jul 2022, 07:29

BoBo, You dont need to send this message.
You need to receive notification about this message from Your bluetooth device.
qwerty12 alreay did it for usb and We need to do the same with our bluetooth device handle and capture GUID_BLUETOOTH_RADIO_IN_RANGE event, I think.
https://docs.microsoft.com/en-us/windows/win32/bluetooth/bluetooth-and-wm-devicechange-messages

Post Reply

Return to “Ask for Help (v1)”