Skip to content

Instantly share code, notes, and snippets.

@TLMcode
Last active November 18, 2020 21:36
Show Gist options
  • Save TLMcode/b56c71ef4785f1ef8daada9c36a38db4 to your computer and use it in GitHub Desktop.
Save TLMcode/b56c71ef4785f1ef8daada9c36a38db4 to your computer and use it in GitHub Desktop.
Change Display Brightness using AHk & WMI
; Variables
Increments := 10 ; < lower for a more granular change, higher for larger jump in brightness
CurrentBrightness := GetCurrentBrightNess()
; Hot Keys
F6::ChangeBrightness( CurrentBrightness -= Increments ) ; decrease brightness
F7::ChangeBrightness( CurrentBrightness += Increments ) ; increase brightness
; Functions
ChangeBrightness( ByRef brightness, timeout = 1 )
{
if ( brightness > 0 && brightness < 100 )
{
For property in ComObjGet( "winmgmts:\\.\root\WMI" ).ExecQuery( "SELECT * FROM WmiMonitorBrightnessMethods" )
property.WmiSetBrightness( timeout, brightness )
}
else if ( brightness >= 100 )
{
brightness := 100
}
else if ( brightness <= 0 )
{
brightness := 0
}
}
GetCurrentBrightNess()
{
For property in ComObjGet( "winmgmts:\\.\root\WMI" ).ExecQuery( "SELECT * FROM WmiMonitorBrightness" )
currentBrightness := property.CurrentBrightness
return currentBrightness
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment