Skip to content

Instantly share code, notes, and snippets.

@krrr
Last active April 26, 2024 15:51
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krrr/3c3f1747480189dbb71f to your computer and use it in GitHub Desktop.
Save krrr/3c3f1747480189dbb71f to your computer and use it in GitHub Desktop.
Windows screen brightness fine tune (autohotkey)
#,::
AdjustScreenBrightness(-3)
Return
#.::
AdjustScreenBrightness(3)
Return
AdjustScreenBrightness(step) {
service := "winmgmts:{impersonationLevel=impersonate}!\\.\root\WMI"
monitors := ComObjGet(service).ExecQuery("SELECT * FROM WmiMonitorBrightness WHERE Active=TRUE")
monMethods := ComObjGet(service).ExecQuery("SELECT * FROM wmiMonitorBrightNessMethods WHERE Active=TRUE")
minBrightness := 5 ; level below this is identical to this
for i in monitors {
curt := i.CurrentBrightness
break
}
if (curt < minBrightness) ; parenthesis is necessary here
curt := minBrightness
toSet := curt + step
if (toSet > 100)
return
if (toSet < minBrightness)
toSet := minBrightness
for i in monMethods {
i.WmiSetBrightness(1, toSet)
break
}
}
@venturqx
Copy link

@Rabelaiss Did you find a solution to display the Brightness OSD on W11 ?

@sameert89
Copy link

sameert89 commented Apr 26, 2024

Updated Script for AHK v2. I could not get the OS brightness popup to work, So I implemented my own tooltip.

; Brightness Control ;

+WheelDown::
{
  AdjustScreenBrightness(-3)
  return
}

+WheelUp::
{
  AdjustScreenBrightness(3)
  return
}

AdjustScreenBrightness(step) {
    service := "winmgmts:{impersonationLevel=impersonate}!\\.\root\WMI"
    monitors := ComObjGet(service).ExecQuery("SELECT * FROM WmiMonitorBrightness WHERE Active=TRUE")
    monMethods := ComObjGet(service).ExecQuery("SELECT * FROM wmiMonitorBrightNessMethods WHERE Active=TRUE")
    minBrightness := 0

    curt := 0 
    for monitor in monitors {
        curt := monitor.CurrentBrightness
        break
    }
    if (curt < minBrightness) {  
        curt := minBrightness
    }
    toSet := curt + step
    if (toSet > 100) {
        ToolTip "Brightness: 100%"
        return
    }
    if (toSet < minBrightness) {
        toSet := minBrightness
    }

    for method in monMethods {
        method.WmiSetBrightness(1, toSet)
        break
    }
    ToolTip "Brightness: " toSet "%"
    SetTimer RemoveToolTip, -1000  ; Remove tooltip after 1 second
}

RemoveToolTip(){
	ToolTip  ; Clears the tooltip
	return
}

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