[AHK-] 改變螢幕亮度(Gamma)

作者: onelife (旺來)   2014-05-10 17:07:43
之前在WOW和D3使用視窗模式時覺得畫面太暗
所以寫了個AHK來做畫面亮度的調整
功能:
切換到指定視窗時自動改變螢幕亮度
操作:
在要調整的視窗內按下Scroll Lock鍵以指定該視窗
之後切換到該視窗時便會自動改變亮度,離開該視窗時還原亮度
右下icon裡的options可設定亮度值
執行檔:
http://www.fileswap.com/dl/zkVWlRTg9r/
調整亮度的寫法參考了下列網址:
brightness.ahk
http://goo.gl/EgTi1s
C#: How to change the color/gamma and brightness
http://goo.gl/7M6xX2
原始碼:
#SingleInstance,force
OnExit, Exit1
SetFormat, FloatFast, 2.2
;建立右下圖示選單
menu,tray, icon, %A_ScriptFullPath%, 1
menu,tray, nostandard
menu,tray, add, Enable, ToggleFunction
menu,tray, add
menu,tray, add, Options, ShowPanel
menu,tray, add, Quit, exit1
menu,tray, default, Enable
menu,tray, check , Enable
;載入設定值
IniRead, myWindow, SetWindowGamma.ini ,SetWindowGamma , TargetWindow,%A_Space%
IniRead, defGamma, SetWindowGamma.ini ,SetWindowGamma , DefaultGamma, 1.0
IniRead, setGamma, SetWindowGamma.ini ,SetWindowGamma , SetGamma, 1.2
IniRead, minGamma, SetWindowGamma.ini ,SetWindowGamma , MinGamma, 0.5
IniRead, maxGamma, SetWindowGamma.ini ,SetWindowGamma , MaxGamma, 2.2
;檢查及初始化設定值
tmp1:=defGamma+setGamma+minGamma+maxGamma
if tmp1 is not number
{
defGamma:=1.0
setGamma:=1.2
minGamma:=0.5
maxGamma:=2.2
gosub SaveSetting
}
else
{
if(maxGamma < minGamma)
{
tmp1:=maxGamma
maxGamma:=minGamma
minGamma:=tmp1
}
if(minGamma<0)
minGamma:=0
if(maxGamma<0)
maxGamma:=3
if(setGamma < minGamma)
setGamma:=minGamma
if(setGamma > maxGamma)
setGamma:=maxGamma
}
barMin:=minGamma*100
barMax:=maxGamma*100
barSet:=setGamma*100
;繪製設定介面
Gui Hidden:New
Gui Hidden:Cancel
Gui MyPanel:New
Gui MyPanel: +OwnerHidden
Gui MyPanel: -Caption +Border +AlwaysOnTop
Gui MyPanel: Add,Text,x11 y26 w49 h23,Program:
Gui MyPanel: Add,Edit,ReadOnly x60 y24 w130 h19,%myWindow%
Gui MyPanel: Add,Text,-wrap x17 y48 w180 h28,(use ScrollLock to select a program)
Gui MyPanel: Add,Groupbox,x15 y86 w172 h104,Gamma:
Gui MyPanel: Add,Text,x58 y113 w36 h18,Set to:
Gui MyPanel: Add,Edit,ReadOnly vMyGamma x91 y111 w35 h21,%setGamma%
Gui MyPanel: Add,Text,x160 y170 w25 h17,%maxGamma%
Gui MyPanel: Add,Text,x24 y169 w25 h17,%minGamma%
Gui MyPanel: Add,Slider,x20 y134 w163 h33 range%barMin%-%barMax% vSlideNum AltSubmit gSlide1,%barSet%
Gui MyPanel: Show,Hide xCenter yCenter w200 h198,SetWindowGammaGUI
Global switch1=1
;切換亮度
Loop
{
WinGet,theProcess,processname,A
WinWaitNotActive, ahk_exe theProcess, ,60
if(switch1==0)
continue
if(ErrorLevel==0)
{
IfWinActive, ahk_exe %myWindow%
SetScreenBrightness(setGamma)
else
SetScreenBrightness(defGamma)
}
}
ShowPanel:
IfWinExist, SetWindowGammaGUI
Gui MyPanel: Cancel
else
{
GuiControl, MyPanel: ,Edit1, %myWindow%
Gui MyPanel: show
}
WinWaitNotActive, SetWindowGammaGUI
SetScreenBrightness(defGamma)
Gui MyPanel: Cancel
return
Slide1:
setGamma:=SlideNum/100
Guicontrol, MyPanel: ,Edit2, %setGamma%
SetScreenBrightness(setGamma)
return
ScrollLock::
if(switch1==0)
{
SendInput {ScrollLock}
return
}
WinGet,theProcess,processname,A
if( myWindow != theProcess )
{
myWindow = %theProcess%
SetScreenBrightness(setGamma)
}
else
SendInput {ScrollLock}
return
ToggleFunction:
Gui MyPanel: Cancel
if(switch1)
{
SetScreenBrightness(defGamma)
menu,tray, Uncheck, Enable
switch1:=0
menu,tray, icon, %A_ScriptFullPath%, 3
}
else
{
menu,tray, Check, Enable
switch1:=1
menu,tray, icon, %A_ScriptFullPath%, 1
}
return
SaveSetting:
IniWrite, %myWindow% , SetWindowGamma.ini ,SetWindowGamma , TargetWindow
IniWrite, %defGamma% , SetWindowGamma.ini ,SetWindowGamma , DefaultGamma
IniWrite, %setGamma% , SetWindowGamma.ini ,SetWindowGamma , SetGamma
IniWrite, %minGamma% , SetWindowGamma.ini ,SetWindowGamma , MinGamma
IniWrite, %maxGamma% , SetWindowGamma.ini ,SetWindowGamma , MaxGamma
return
Exit1:
SetScreenBrightness(defGamma)
gosub SaveSetting
ExitApp
SetScreenBrightness(brightness)
{
if( (hDesktopDC := DllCall("GetDC", uint, 0, uint)) = 0 )
return False
arraysize := 256*2
VarSetCapacity(ramp, 3*arraysize, 0)
Loop, 256
{
;
作者: SilentWorld (June)   2014-05-12 21:21:00
感謝提供!

Links booklink

Contact Us: admin [ a t ] ucptt.com