Last active
April 29, 2019 13:55
-
-
Save Saibot942/f578e19954b4765c06996bfcd383d274 to your computer and use it in GitHub Desktop.
Screen dimming hack for desktop computers (mimics laptop brightness controls)
This file contains 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
; ======================================================================== | |
; Screen dimming hack for desktop computers (mimics laptop brightness controls) | |
; ======================================================================== | |
; | |
; Version: 2017.01.30 | |
; Adapted: Toby Garcia | |
; Source: https://gist.github.com/Saibot942/f578e19954b4765c06996bfcd383d274 | |
; | |
; Original: jNizM | |
; Source: https://www.autohotkey.com/boards/viewtopic.php?p=42396#p42396 | |
; | |
; ======================================================================== | |
; | |
; Brightness can go above 100% of default, but I have created no presets >128. | |
; Troubleshooting: NumLock must be enabled for the presets to work. | |
#NumpadSub:: AdjustBrightness(-1) ; decrease gamma value by 1 (-1) | |
#NumpadAdd:: AdjustBrightness(+1) ; increase gamma value by 1 (+1) | |
#NumpadDot:: DisplaySetBrightness(128) ; set gamma to standard value (100%) | |
#Numpad7:: DisplaySetBrightness(96) ; set gamma to 75% of standard value | |
#Numpad5:: | |
DisplaySetBrightness(65) ; this jitter is ugly but necessary for consistent results | |
DisplaySetBrightness(64) ; set gamma to 50% of standard value | |
return | |
#Numpad2:: | |
DisplaySetBrightness(33) ; this jitter is ugly but necessary for consistent results | |
DisplaySetBrightness(32) ; set gamma to 25% of standard value | |
return | |
#Numpad0:: | |
DisplaySetBrightness(1) ; this jitter is ugly but necessary for consistent results | |
DisplaySetBrightness(0) ; set gamma to minimum value (0%) | |
return | |
;======================================================================================== | |
AdjustBrightness(V = 0) | |
{ | |
SB := (SB := DisplayGetBrightness() + V) > 255 ? 255 : SB < 0 ? 0 : SB | |
DisplaySetBrightness(SB) | |
} | |
DisplaySetBrightness(SB := 128) | |
{ | |
loop % VarSetCapacity(GB, 1536) / 6 | |
NumPut((N := (SB + 128) * (A_Index - 1)) > 65535 ? 65535 : N, GB, 2 * (A_Index - 1), "UShort") | |
DllCall("RtlMoveMemory", "Ptr", &GB + 512, "Ptr", &GB, "Ptr", 512) | |
DllCall("RtlMoveMemory", "Ptr", &GB + 1024, "Ptr", &GB, "Ptr", 512) | |
return DllCall("gdi32.dll\SetDeviceGammaRamp", "Ptr", hDC := DllCall("user32.dll\GetDC", "Ptr", 0), "Ptr", &GB), DllCall("user32.dll\ReleaseDC", "Ptr", 0, "Ptr", hDC) | |
} | |
DisplayGetBrightness(ByRef GB := "") | |
{ | |
VarSetCapacity(GB, 1536, 0) | |
DllCall("gdi32.dll\GetDeviceGammaRamp", "Ptr", hDC := DllCall("user32.dll\GetDC", "Ptr", 0), "Ptr", &GB) | |
return NumGet(GB, 2, "UShort") - 128, DllCall("user32.dll\ReleaseDC", "Ptr", 0, "Ptr", hDC) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Win+NumpadSub -- decrease gamma value by 1 (-1)
Win+NumpadAdd -- increase gamma value by 1 (+1)
Win+NumpadDot -- set gamma to standard value (100%)
Win+Numpad7 -- set gamma to 75% of standard value
Win+Numpad5 -- set gamma to 50% of standard value
Win+Numpad2 -- set gamma to 25% of standard value
Win+Numpad0 -- set gamma to minimum value (0%)