AHK调整屏幕亮度

AHK调整屏幕亮度

ALT+Z变亮,Alt+X变暗

;来源:https://autohotkey.com/board/topic/83100-laptop-screen-brightness/
;#NoEnv
;#AllowSameLineComments
;#SingleInstance force
;#InstallKeybdHook
;#NoTrayIcon

;SetWorkingDir %A_ScriptDir%
;SendMode, Input

!z::
	MoveBRightness(1)
return

!x::
	MoveBRightness(-1)
return

MoveBrightness(IndexMove)
{

	VarSetCapacity(SupportedBRightness, 256, 0)
	VarSetCapacity(SupportedBRightnessSize, 4, 0)
	VarSetCapacity(BRightnessSize, 4, 0)
	VarSetCapacity(BRightness, 3, 0)

	hLCD := DllCall("CreateFile"
		, Str, "\\.\LCD"
		, UInt, 0x80000000 | 0x40000000 ;Read | Write
		, UInt, 0x1 | 0x2  ; File Read | File Write
		, UInt, 0
		, UInt, 0x3        ; open any existing file
		, UInt, 0
		, UInt, 0)

	if hLCD != -1
	{
		DevVideo := 0x00000023, BuffMethod := 0, Fileacces := 0
		NumPut(0x03, BRightness, 0, "UChar")      ; 0x01 = Set AC, 0x02 = Set DC, 0x03 = Set both
		NumPut(0x00, BRightness, 1, "UChar")      ; The AC bRightness level
		NumPut(0x00, BRightness, 2, "UChar")      ; The DC bRightness level
		DllCall("DeviceIoControl"
			, UInt, hLCD
			, UInt, (DevVideo<<16 | 0x126<<2 | BuffMethod<<14 | Fileacces) ; IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS
			, UInt, 0
			, UInt, 0
			, UInt, &Brightness
			, UInt, 3
			, UInt, &BrightnessSize
			, UInt, 0)

		DllCall("DeviceIoControl"
			, UInt, hLCD
			, UInt, (DevVideo<<16 | 0x125<<2 | BuffMethod<<14 | Fileacces) ; IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS
			, UInt, 0
			, UInt, 0
			, UInt, &SupportedBrightness
			, UInt, 256
			, UInt, &SupportedBrightnessSize
			, UInt, 0)

		ACBRightness := NumGet(BRightness, 1, "UChar")
		ACIndex := 0
		DCBRightness := NumGet(BRightness, 2, "UChar")
		DCIndex := 0
		BufferSize := NumGet(SupportedBRightnessSize, 0, "UInt")
		MaxIndex := BufferSize-1

		loop, %BufferSize%
		{
			ThisIndex := A_Index-1
			ThisBRightness := NumGet(SupportedBRightness, ThisIndex, "UChar")
			if ACBRightness = %ThisBRightness%
				ACIndex := ThisIndex
			if DCBRightness = %ThisBRightness%
				DCIndex := ThisIndex
		}

		if DCIndex >= %ACIndex%
			BRightnessIndex := DCIndex
		else
			BRightnessIndex := ACIndex

		BRightnessIndex += IndexMove

		if BRightnessIndex > %MaxIndex%
			BRightnessIndex := MaxIndex

		if BRightnessIndex < 0
			BRightnessIndex := 0

		NewBRightness := NumGet(SupportedBRightness, BRightnessIndex, "UChar")

		NumPut(0x03, BRightness, 0, "UChar")               ; 0x01 = Set AC, 0x02 = Set DC, 0x03 = Set both
		NumPut(NewBRightness, BRightness, 1, "UChar")      ; The AC bRightness level
		NumPut(NewBRightness, BRightness, 2, "UChar")      ; The DC bRightness level

		DllCall("DeviceIoControl"
			, UInt, hLCD
			, UInt, (DevVideo<<16 | 0x127<<2 | BuffMethod<<14 | Fileacces) ; IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS
			, UInt, &Brightness
			, UInt, 3
			, UInt, 0
			, UInt, 0
			, UInt, 0
			, Uint, 0)

		DllCall("CloseHandle", UInt, hLCD)

	}

}

 

给TA捐赠
共{{data.count}}人
人已捐赠
其他

toralf版Windows窗口信息获取(AHK_Window_Info_v1.7)

2018-1-12 9:29:59

其他

AHK实现根据程序配置输入法

2018-1-13 19:31:55

3 条回复 A文章作者 M管理员
  1. 点点丹枫

    太强了,谢谢大佬

  2. jameshoo007

    这个是不是只有支持的屏幕才可以,以前旧屏幕可能不行

  3. wangyq123123

    试了不能用啊。

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索