这里有 3 种调暗屏幕的方法。
- 使用 powrprof.dll 更改笔记本电脑的亮度。注意:这不会影响电视等外部设备(其他 2 个设备会影响)。基于 qwerty12 的代码。
- 使用 GetDeviceGammaRamp/SetDeviceGammaRamp 更改屏幕亮度。注意:这可能与 f.lux 使用的方法相同。基于 jNizM 的代码。
- 使用具有不同透明度的全黑 GUI。注意:这会影响打印屏幕,除非您使用窗口消息暂时将其关闭(其他两个不影响打印屏幕)。
注意:我建议您在首次使用脚本时在某处记录亮度设置,然后再使用脚本更改这些值。
出处:https://www.autohotkey.com/boards/viewtopic.php?f=6&t=39580
;based on code by qwerty12: ;Set laptop brightness & show Win 10's native OSD - AutoHotkey Community ;https://autohotkey.com/boards/viewtopic.php?f=6&t=26921 F1:: ;get AC/DC brightness F2:: ;set AC brightness F3:: ;set DC brightness ;note: AC is the brightness when the laptop is plugged in DllCall("powrprof\PowerGetActiveScheme", Ptr,0, PtrP,vActivePolicyGuid, UInt) VarSetCapacity(GUID_VIDEO_SUBGROUP, 16) NumPut(0x7516B95F, &GUID_VIDEO_SUBGROUP, 0, "UInt"), NumPut(0x4464F776, &GUID_VIDEO_SUBGROUP, 4, "UInt") NumPut(0x1606538C, &GUID_VIDEO_SUBGROUP, 8, "UInt"), NumPut(0x99CC407F, &GUID_VIDEO_SUBGROUP, 12, "UInt") VarSetCapacity(GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS, 16) NumPut(0xADED5E82, &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS, 0, "UInt"), NumPut(0x4619B909, &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS, 4, "UInt") NumPut(0xD7F54999, &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS, 8, "UInt"), NumPut(0xCB0BAC1D, &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS, 12, "UInt") DllCall("powrprof\PowerReadACValueIndex", Ptr,0, Ptr,vActivePolicyGuid, Ptr,&GUID_VIDEO_SUBGROUP, Ptr,&GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS, UIntP,vBrightnessAC, UInt) DllCall("powrprof\PowerReadDCValueIndex", Ptr,0, Ptr,vActivePolicyGuid, Ptr,&GUID_VIDEO_SUBGROUP, Ptr,&GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS, UIntP,vBrightnessDC, UInt) ;e.g. 46 40 if InStr(A_ThisHotkey, "q") MsgBox, % "AC brightness: " vBrightnessAC "`r`n" "DC brightness: " vBrightnessDC if InStr(A_ThisHotkey, "w") { InputBox, vBrightnessAC2,, % vPrompt,,,,,,,, % vBrightnessAC if !(vBrightnessAC2 = vBrightnessAC) { DllCall("powrprof\PowerWriteACValueIndex", Ptr,0, Ptr,vActivePolicyGuid, Ptr,&GUID_VIDEO_SUBGROUP, Ptr,&GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS, UInt,vBrightnessAC2, UInt) DllCall("powrprof\PowerSetActiveScheme", Ptr,0, Ptr,vActivePolicyGuid, UInt) } } if InStr(A_ThisHotkey, "e") { InputBox, vBrightnessDC2,, % vPrompt,,,,,,,, % vBrightnessDC if !(vBrightnessDC2 = vBrightnessDC) { DllCall("powrprof\PowerWriteDCValueIndex", Ptr,0, Ptr,vActivePolicyGuid, Ptr,&GUID_VIDEO_SUBGROUP, Ptr,&GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS, UInt,vBrightnessDC2, UInt) DllCall("powrprof\PowerSetActiveScheme", Ptr,0, Ptr,vActivePolicyGuid, UInt) } } return
;based on code by jNizM: ;GitHub - jNizM/Class_Monitor: Monitor Class (WinAPI) ;https://github.com/jNizM/Class_Monitor ;Class Monitor (Brightness, ColorTemperature) - AutoHotkey Community ;https://autohotkey.com/boards/viewtopic.php?f=6&t=7854 ;e.g. f.lux on/off ;RGB: 129,69,5 ;e.g. f.lux on ;RGB: 129,129,129 ;e.g. f.lux off q:: ;get brightness VarSetCapacity(vData, 1536, 0) hDC := DllCall("user32\GetDC", Ptr,0, Ptr) DllCall("gdi32\GetDeviceGammaRamp", Ptr,hDC, Ptr,&vData) vColR := NumGet(vData, 2, "UShort") - 128 vColG := NumGet(vData, 512+2, "UShort") - 128 vColB := NumGet(vData, 1024+2, "UShort") - 128 DllCall("user32\ReleaseDC", Ptr,0, Ptr,hDC) MsgBox, % Format("RGB: {:i},{:i},{:i}", vColR, vColG, vColB) ;e.g. RGB: 127,127,125 MsgBox, % Format("red: {:i}`r`n" "green: {:i}`r`n" "blue: {:i}", vColR, vColG, vColB) return w:: ;set brightness e:: ;set brightness (default values) vColRGB := "1,1,1" vColRGB := "32,32,32" vColRGB := "64,64,64" vColRGB := "128,128,128" vColRGB := "255,255,255" if InStr(A_ThisHotkey, "e") vColRGB := "127,127,125" oArray := StrSplit(vColRGB, ",") vColR := oArray.1+128, vColG := oArray.2+128, vColB := oArray.3+128, oArray := "" VarSetCapacity(vData, 1536, 0) Loop, % 1536 / 6 { vIndex := A_Index-1 NumPut((vR := vColR*vIndex) > 65535 ? 65535 : vR, vData, 2*vIndex, "UShort") NumPut((vG := vColG*vIndex) > 65535 ? 65535 : vG, vData, 512 + 2*vIndex, "UShort") NumPut((vB := vColB*vIndex) > 65535 ? 65535 : vB, vData, 1024 + 2*vIndex, "UShort") } hDC := DllCall("user32\GetDC", Ptr,0, Ptr) DllCall("gdi32\SetDeviceGammaRamp", Ptr,hDC, Ptr,&vData) DllCall("user32\ReleaseDC", Ptr,0, Ptr,hDC) return
;'z dimmer.ahk' by jeeswg OnMessage(0x5555, "MsgMonitor") OnMessage(0x5556, "MsgMonitor2") OnMessage(0x5557, "MsgMonitor3") ;handle command line parameter / request brightness vBright = %1% if (vBright = "") { vBright2 := 50 InputBox, vBright,, % "brightness (%) (0=dark, 100=bright)",,,,,,,, % vBright2 if ErrorLevel return } WinGet, hWnd, ID, A ;convert % brightness to value for darkness (opacity of black screen) ;0% bright -> 255/255 black ;50% bright -> 128/255 black ;100% bright -> 0/255 black vNum := Round(((100-vBright)/100) * 255) if (vNum <= 0) ExitApp else if (vNum >= 255) vNum := 255 ;specify a number between 0 (invisible) and 255 (opaque) ;bigger number = darker screen Gui, Color, 000000 ;WS_EX_TRANSPARENT := 0x20 (click-through) Gui, -Caption +AlwaysOnTop +E0x20 +HwndhGui +ToolWindow Gui, Show, % Format("x0 y0 w{} h{}", A_ScreenWidth, A_ScreenHeight), dimmer WinSet, Transparent, % vNum, % "ahk_id " hGui WinActivate, % "ahk_id " hWnd return ;================================================== ;hide window (turn dimmer off) MsgMonitor(wParam, lParam, uMsg) { global Gui, Hide } ;show window (turn dimmer on) MsgMonitor2(wParam, lParam, uMsg) { global WinGet, hWnd, ID, A Gui, Show WinActivate, % "ahk_id " hWnd } ;return dimmer level MsgMonitor3(wParam, lParam, msg) { global return vBright } ;================================================== /* ;lines required for other script ;e.g. turn dimmer on/off while do a printscreen vDHW := A_DetectHiddenWindows DetectHiddenWindows, On vTMM := A_TitleMatchMode SetTitleMatchMode, 2 if hWnd := WinExist("\z dimmer.ahk - AutoHotkey ahk_class AutoHotkey") SendMessage, 0x5555,,,, % "ahk_id " hWnd ;turn dimmer off DetectHiddenWindows, % vDHW SetTitleMatchMode, % vTMM vDHW := A_DetectHiddenWindows DetectHiddenWindows, On vTMM := A_TitleMatchMode SetTitleMatchMode, 2 if hWnd := WinExist("\z dimmer.ahk - AutoHotkey ahk_class AutoHotkey") PostMessage, 0x5556,,,, % "ahk_id " hWnd ;turn dimmer on DetectHiddenWindows, % vDHW SetTitleMatchMode, % vTMM */ ;==================================================
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)