Last active
December 19, 2024 17:11
-
-
Save alimbada/9bd28e5a8fb98b1e96cbea8db1cda2b2 to your computer and use it in GitHub Desktop.
Intercept keyboard volume control keys to control LG TV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) | |
} | |
} |
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
Requires https://github.com/klattimer/LGWebOSRemote
.\lgtv-venv\Scripts\activate.bat
instead ofsource lgtv-venv/bin/activate
**