Skip to content

Instantly share code, notes, and snippets.

@alimbada
Last active May 2, 2024 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alimbada/9bd28e5a8fb98b1e96cbea8db1cda2b2 to your computer and use it in GitHub Desktop.
Save alimbada/9bd28e5a8fb98b1e96cbea8db1cda2b2 to your computer and use it in GitHub Desktop.
Intercept keyboard volume control keys to control LG TV
#Requires AutoHotkey v2.0
#SingleInstance
Volume_Up::
{
audio_device := SoundGetName()
If InStr(audio_device, "LG TV SSCR2")
Run "lgtv --name MyTV --ssl volumeUp", , "Hide"
Else
VolumeOSD "+5"
}
Volume_Down::
{
audio_device := SoundGetName()
If InStr(audio_device, "LG TV SSCR2")
Run "lgtv --name MyTV --ssl volumeDown", , "Hide"
Else
VolumeOSD "-5"
}
/**
* changes volume and show volume OSD
* @param vol - same param as SoundSetVolume. If vol is "M" or "Mute", volume will toggle mute.
*/
VolumeOSD(vol) {
(vol ~= "i)^(M|Mute)$")
? SoundSetMute(-1)
: SoundSetVolume(vol) ; Use a string "+1" or "-1"
CLSID_ImmersiveShell := "{C2F03A33-21F5-47FA-B4BB-156362A2F239}"
IID_Unknown := "{00000000-0000-0000-C000-000000000046}"
IID_IAudioFlyoutController := "{41f9d2fb-7834-4ab6-8b1b-73e74064b465}"
try if shellProvider := ComObject(CLSID_ImmersiveShell, IID_Unknown) {
try if flyoutDisp := ComObjQuery(shellProvider, IID_IAudioFlyoutController, IID_IAudioFlyoutController)
ComCall(3, flyoutDisp, "int", 0, "uint", 0)
}
}
@alimbada
Copy link
Author

alimbada commented Jul 20, 2023

Requires https://github.com/klattimer/LGWebOSRemote

  1. Install Python via winget
  2. Follow instructions on klattimer/LGWebOSRemote. Use .\lgtv-venv\Scripts\activate.bat instead of source lgtv-venv/bin/activate**
  3. Install AutoHotkey via winget
  4. Run the script
  5. Optional: set it to run at startup: https://www.autohotkey.com/docs/v2/FAQ.htm#Startup

@alimbada
Copy link
Author

Thanks to /u/plankoe on reddit for the VolumeOSD function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment