SOLVED

Media Keys and Teams notifications

Brass Contributor

If I use keyboard media keys to pause music when I receive a call in teams, the notification sound doesn't seem to get dismissed when I answer the call. So, when I later press play, it also resumes playing the teams call sound over my music. 

 

It does seem to go away on it's own eventually, but it's kind of annoying when I want to listen to music!

graemec5_0-1606932042920.png

 

47 Replies
Ah yes, that was the issue, thanks!! Guess I just gotta change my shortcuts 🙂 Hope this helps someone else hitting the same issue!
Has anyone found a new workaround for this that doesn't involve hex editing? Been using the HardwareMediaKeyHandling disable fix for a while before it broke but I'd rather not be changing the exe for this, no matter how frustrating this bug is.

I had some fun automating the process of changing the Teams executable. First iterations took about 10 to 15 minutes to complete but this one does the job in about 5 seconds. You don't have to use it if you don't trust it but it sets the original EXE aside so if something wrong happens, you can just replace the resulting file from this script with the original

 

# Getting the filepath for Teams.exe
$FilePath = Join-Path -Path $env:LOCALAPPDATA -ChildPath "Microsoft\Teams\current\Teams.exe"

# Killing all instances of Teams.exe
Get-Process | ? { $_.Path -eq $FilePath} | Stop-Process -Force -Confirm:$False

# Get the Hex and Binary format of the option "HardwareMediaKeyHandling"
$Option = "HardwareMediaKeyHandling"
$HWMKeyHandlingHexArray = ($Option.ToCharArray() | % { [String]::Format("{0:X2}", [System.Convert]::ToUInt32($_)) }) -Join "-"
$HWMKeyHandlingByteArray = [Byte[]]($HWMKeyHandlingHexArray.split("-") | % { "0x{0}" -f $_ })

# Other needed variables
$ValueOffset = 8
$OldValue = 1
$NewValue = 0

# Get Teams as ByteArray and Hex String
$Bytes = [System.IO.File]::ReadAllBytes($FilePath);
$Hex = [System.BitConverter]::ToString($Bytes)

# Get the location of the option in de HexString
$HexIndex = $Hex.IndexOf($HWMKeyHandlingHexArray)

# Calculate the index of the hex to the index of the byte array
# Account for the dashes in the string
$Index = $HexIndex * 2 / 3
# Account for the fact that HEX makes couples of 2 characters for a byte
$Index = $Index / 2

# Build in some safety
$GotIt = $True

For ($i = 0 ; $i -lt $HWMKeyHandlingByteArray.Count ; $i++) {
    If ($Bytes[($Index + $i)] -ne $HWMKeyHandlingByteArray[$i]) {
        $GotIt = $False
    }
}

If ($GotIt -eq $False) {
    "Something went wrong calculating the exact location of '{0}'" -f $Option
    Break
}
Else {
    # Checking for the value of the option
    $ValueIndex = $Index + $HWMKeyHandlingByteArray.count + $ValueOffset
    
    If ($Bytes[$ValueIndex] -eq $OldValue) {
        # Actually setting the value
        "Changing the value of option '{0}' from {1} to {2}" -f $Option, $OldValue, $NewValue
        $Bytes[$ValueIndex] = $NewValue

        # Set aside the old file for if something went wrong despite the checks in this script
        $File = Get-Item -Path $FilePath
        $CopyFilePath = Join-Path -Path $File.DirectoryName -ChildPath ("{0}.old{1}" -f $File.BaseName,$File.Extension)
        [Void](Copy-Item -Path $FilePath -Destination $CopyFilePath -Force:$False -Confirm:$False)

        # Write new teams.exe
        [System.IO.File]::WriteAllBytes($FilePath, $Bytes)
    }
    ElseIf ($Bytes[$ValueIndex] -eq $NewValue) {
        "No need to update the value: '{0}' is already set to {1}" -f $Option, $NewValue
    }
    Else {
        "Something isn't correct, the value for option '{0}' is neither {1} or {2} but {3}" -f $Option, $OldValue, $NewValue, $Bytes[$ValueIndex]
    }
}

 

This HEX editing method is the only workable one I've found. It does **bleep** up the Digital Signature so it could get flagged by some EDRs but nothing yet from FortiEDR here.

This one was the answer for me, I was still using the "update" file in the shortcut to open, no one said anything previously about having to change that for the hex editing option..
it's so completely like microsoft to break their application so badly
there is absolutely NO reason media keys should be enabled in Teams whatsoever, so having to delve so deeply to fix the option being forced-enabled for something that shouldn't exist as a "feature" is beyond me.

but yes, thanks very much now to all those who have commented prior to me, Dawust in particular for pointing out that you can in fact start Teams just via the Teams.exe 😄

microsoft, your support and business practices are so abhorent.

@Hofa Your script gives me this result: 

Something isn't correct, the value for option 'HardwareMediaKeyHandling' is neither 1 or 0 but 72

@OudstandCan you add this in the last Else clause, run the script again and report back with the output?:

 

[System.BitConverter]::ToString(($Bytes[$ValueIndex..($HWMKeyHandlingByteArray.count + $ValueOffset + 10)]))

 

@Hofa the output is longer than the console can display it. I could post the code which is still shown in the console window. Do you want me to do this?

Oh my bad. Updated:

 

[System.BitConverter]::ToString(($Bytes[$ValueIndex..($ValueIndex + $HWMKeyHandlingByteArray.count + $ValueOffset + 10)]))

 

@Hofa Hey i think Teams got recently updated (I have to redo the hex edit).

 

This is what i got when run your script

 

PS C:\Users\User\OneDrive\Workstation> .\Teams_DisableMediaKeysHex.ps1
Something isn't correct, the value for option 'HardwareMediaKeyHandling' is neither 1 or 0 but 72
48-E7-09-47-01-00-00-00-01-00-00-00-00-00-00-00-52-65-73-6F-6C-75-74-69-6F-6E-42-61-73-65-64-44-65-63-6F-64-65-72-50-72-69-6F-72

 

I get the same result.
@MrDak, teams was updated 22nd for me.

I can see...
4861726477617265 4D656469614B6579
48616E646C696E67 0000000000000000
48E7094701000000 0100000000000000

Looks to me @Hofa that the $ValueOffset should be 16, not 8

**bleep**, looks like the number of bytes between the optionName and it's value is different on my setup. It should work when you change 'offset' on line 13 from 8 to 12... I think...

Works with 16 as the offset for me

@Hofa 

works great on teams 1.5.0.31168 using 16 as the offset, many thanks for providing this script.

Holy %$^& - at this rate it'll be faster for me to Alt F4 teams after each meeting. Hmm, actually a macro app would do that nicely...

C'mon MS Devs - pull your heads out of your fundaments and delete the abomnibal code from Teams!

How was this ever written into the code of MS Teams to begin with?!?!

Do you happen to have the full script (with updates) to github gists or something similar? 😄 Because if i execute the script, both with offset 12 or 16, teams wont start anymore 😞

you need to run teams.exe directly I suspect you are running the update.exe if you are using an existing shortcut. That'll fail when it detects the change to teams.exe I believe.
Teams started hijacking my media keys a few days ago (specifically the play/pause button). Instead of playing the call notification sound (like it did for the past year), nothing happens now. Close Teams, and play button actually plays my music.

However, I noticed something interesting, If I press Ctrl+Play or Shift+Play (and maybe other modifier keys), my music plays and Teams ignores it. This doesn't fix the problem, I have to press Ctrl+Play every time. However, if this continues I'm going to setup AutoHotKey to change Play/Pause to Ctrl+Play/Pause permanently.

Can anyone else replicate my finding? Additional detail, I play music using YouTube Music in Chrome.

@Tpolz Wow interesting.  Yep, just tried it and it worked for me.  Sort of.  At first I tried left ctrl+play and it didn't work (it played the Teams call sound).  So I did left ctrl+play again to turn that sound off.  Then I tried right ctrl+play and it played my spotify music.  Huzzah!  

 

So then I tried left ctrl+play again and this time it played spotify.  WTF is going on.

 

Nice find, btw.