Skip to content

Instantly share code, notes, and snippets.

@anonymous1184
Last active May 15, 2024 13:57
Show Gist options
  • Save anonymous1184/9761e07daeb9e7dd2ac169eb4024f065 to your computer and use it in GitHub Desktop.
Save anonymous1184/9761e07daeb9e7dd2ac169eb4024f065 to your computer and use it in GitHub Desktop.
Brightness changer + OSD

; Version: 2022.11.17.1
; Usage and examples: https://redd.it/owgn3j
Brightness(Offset) {
static last := ""
wmi := ComObjGet("winmgmts:\\.\root\WMI")
if (last = "") {
last := wmi.ExecQuery("SELECT * FROM WmiMonitorBrightness")
.ItemIndex(0)
.CurrentBrightness
}
DetectHiddenWindows On
hWnd := DllCall("FindWindowA", "AStr","NativeHWNDHost", "Ptr",0, "Ptr")
PostMessage 0xC028, 0x037,,, % "ahk_id" hWnd
brightness := Min(100, Max(0, last + Offset))
if (brightness = last)
return
last := brightness
wmi.ExecQuery("SELECT * FROM WmiMonitorBrightnessMethods")
.ItemIndex(0)
.WmiSetBrightness(0, brightness)
ObjRelease(wmi)
}
@Lorenzo501
Copy link

Would be pretty cool if this can be used to automatically regulate brightness for HDR monitors, based on having a certain amount of vibrant grey/white pixels being detected in any internet browser (or just chrome), with the exception of videos played in the browser.

I have a HDR monitor and always leave HDR on, it'd be unbearable if it wasn't for the chrome extension called "Dark Reader". But the caveat is that "Dark Reader" can't always get the colors right, sometimes it's so bad you can't even read text b/c of it. So to fix this I have a bookmark called "RESET COLORS" with the following content: "javascript:const lock = document.createElement('meta');lock.name = 'darkreader-lock';document.head.appendChild(lock);".

This resets the effect of "Dark Reader" on the webpage, to make the colors temporarily normal again (which is sometimes ofc very bright as well). It's also quite a hassle to set up "Dark Reader" for the many websites that I want it to work on. So if you ever make a browser-based brightness regulator for HDR monitors, I would love to have it! Seems too challenging for me to make myself tbh, especially the part where you detect a video being played in the browser. But if you have info regarding that, you could share it with me if you want^^ Then maybe I'll manage to figure out the rest.

@anonymous1184
Copy link
Author

automatically regulate

Is completely out of the scope (this is for manual adjustment). Most likely there should be tools for that, and others that overlap with HDR stuff.

@Lorenzo501
Copy link

Lorenzo501 commented Oct 21, 2023

automatically regulate

Is completely out of the scope (this is for manual adjustment). Most likely there should be tools for that, and others that overlap with HDR stuff.

Thanks so much, you were right and now I no longer need to bother with the javascript bookmark!
There is one chrome extension that does this: "Sites Dimmer - sharp brightness reduction". Paired with "Dark Reader" it does an amazing job.
I'm now using "Dark Reader" to affect only several websites that I've configured it for and I made sure that "Sites Dimmer - sharp brightness reduction" wasn't affecting those, but any other website with bright colors will be set to 85% brightness automatically.
Why I'm still using "Dark Reader" is b/c I quite like the custom dark theme that I have for some websites. So using both is really nice.

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