Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

How to adjust display brightness? (I'm sure it's possible)


  • Please log in to reply
26 replies to this topic
dvda2k
  • Members
  • 48 posts
  • Last active: Mar 12 2012 09:41 AM
  • Joined: 19 Apr 2007
In Vista and Win 7, you can press Win + X to use Windows Mobility Center to adjust your LCD backlight. Windows Mobility Center talks to your graphics driver.

I searched MSDN and found some articles talking about "Backlight Control Interface". But I just don't know how to implement this code into Autohotkey.

Can anyone help? The MSDN link is here:
<!-- m -->http://msdn.microsof.../aa372656(VS.85<!-- m -->).aspx

BoBo³
  • Guests
  • Last active:
  • Joined: --
[OT]
OK. We often see 'half-converted' URLs used within the forum, like the following one (taken from above):
http://msdn.microsof...ibrary/aa372656(VS.85).aspx

The reason is the use of special characters, here ---> ( ), which won't be translated by the forum software phpBB. A quick one to help yourself is to drop the link into Google and search for it. You can extract the (now) converted special characters afterwards from the (converted) link which is shown at the address bar.
http://msdn.microsof...ry ... 85).aspx
[/OT]

BoBo³
  • Guests
  • Last active:
  • Joined: --
OR ...
feel free to have a try to translate the string/URL with Autohotkey. 8)

HTML, String: Converts String into its HTML equivalent by translating characters whose ASCII values are above 127 to their HTML names (e.g. £ becomes £). In addition, the four characters "&<> are translated to "&<>. Finally, each linefeed (`n) is translated to
`n (i.e.
followed by a linefeed).



dvda2k
  • Members
  • 48 posts
  • Last active: Mar 12 2012 09:41 AM
  • Joined: 19 Apr 2007
BoBo³, thanks for your reply. Fortunately the MSDN website has some error-proof feature, the broken URL still gets you to the right place.

Do you have any comment on my question itself?

..:: Free Radical ::..
  • Members
  • 74 posts
  • Last active: May 30 2015 12:13 PM
  • Joined: 20 Sep 2006
I humbly second that request for IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS

..:: Free Radical ::..
  • Members
  • 74 posts
  • Last active: May 30 2015 12:13 PM
  • Joined: 20 Sep 2006
hLCD = CreateFile( "\\.\LCD" , #GENERIC_READ | #GENERIC_WRITE , #FILE_SHARE_READ | #FILE_SHARE_WRITE , #Null , #OPEN_EXISTING , #Null , #Null )

DeviceIoControl( hLCD , #IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS , #Null , #Null , MDB  , SizeOf ( MDB  ) , @ lReturnedBytes , #Null )

DeviceIoControl( hLCD , #IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS , SDB , SizeOf ( tDisplayBrightness ) , #Null , #Null , @ returnedBytes , #Null)

Can someone help me write the appropriate dllcall?
hLCD := DllCall("CreateFile", "str", "\\.\LCD", "Uint", 0, "Uint", 3, "Uint", 0, "Uint", 3, "Uint", 0, "Uint", 0)
SUPPORTED_BRIGHTNESS := DllCall("DeviceIoControl", "Uint", hLCD, "Uint", 0x125, "Uint", 0, "Uint", 0, "str", 0, "str", 256, "Uint", 0, "Uint", 0)


temp01
  • Members
  • 120 posts
  • Last active: May 18 2013 08:27 PM
  • Joined: 09 Jul 2009
Does this work (I don't have an LCD monitor to test)? If not, what does the msgbox show?
hLCD := DllCall("CreateFile"
	, Str, "\\.\LCD"
	, UInt, 0x80000000 | 0x40000000  ; GENERIC_READ | GENERIC_WRITE
	, UInt, 0x1 | 0x2  ; FILE_SHARE_READ | FILE_SHARE_WRITE
	, UInt, 0
	, UInt, 0x3  ; OPEN_EXISTING
	, UInt, 0, UInt, 0)
if hLCD <> -1
{
	FILE_DEVICE_VIDEO := 0x00000023, METHOD_BUFFERED := 0, FILE_ANY_ACCESS := 0
	VarSetCapacity(DISPLAY_BRIGHTNESS, 3, 0)
		NumPut(0x03, DISPLAY_BRIGHTNESS, 0, "UChar")	; 0x01 = Set AC, 0x02 = Set DC, 0x03 = Set both
		NumPut(50, DISPLAY_BRIGHTNESS, 1, "UChar")		; The AC brightness level
		NumPut(50, DISPLAY_BRIGHTNESS, 2, "UChar")		; The DC brightness level
	Msgbox % ""
	. DllCall("DeviceIoControl"
		, UInt, hLCD
		, UInt, (FILE_DEVICE_VIDEO<<16 | 0x127<<2 | METHOD_BUFFERED<<14 | FILE_ANY_ACCESS) ; IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS
		, UInt, &DISPLAY_BRIGHTNESS, UInt, 3
		, UInt, 0, UInt, 0
		, UIntP, dwBytesReturned  ; Unused.
		, UInt, 0) "`nErrorLevel:`t`t" ErrorLevel "`nLastError:`t`t" A_LastError
	DllCall("CloseHandle", UInt, hLCD)
}
(based on this code (remarks))

..:: Free Radical ::..
  • Members
  • 74 posts
  • Last active: May 30 2015 12:13 PM
  • Joined: 20 Sep 2006
Doesn't work :(
I am on a desktop LCD (AC power). Don't have a laptop.

Msgbox Output:

1
Errorlevel :  0
Last Error:  0


temp01
  • Members
  • 120 posts
  • Last active: May 18 2013 08:27 PM
  • Joined: 09 Jul 2009
Try the code again (fixed NumPut offsets).

..:: Free Radical ::..
  • Members
  • 74 posts
  • Last active: May 30 2015 12:13 PM
  • Joined: 20 Sep 2006
Same output and no effect. Perhaps my LCD doesn't support backlight control.

Can anyone else test this too?

FreeRadical
  • Guests
  • Last active:
  • Joined: --
Thanks for al the help temp0 :). I hope we figure this out someday.

pajenn
  • Members
  • 391 posts
  • Last active: Feb 06 2015 07:57 AM
  • Joined: 07 Feb 2009

1
Errorlevel : 0
Last Error: 0


Same here. I can adjust my laptop LCD brightness with fn+f9/f10, but AHK cannot detect the 'fn' key (no sc/vk code) so I cannot remap it -- I'd prefer to use the mouse scroll wheel...

Hardware: fast laptop with SSD
Software: Win 7 Home Premium 64-bit, android for phone and tablet


temp01
  • Members
  • 120 posts
  • Last active: May 18 2013 08:27 PM
  • Joined: 09 Jul 2009
I think what you want is SetMonitorBrightness not IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS

8
  • Members
  • 1 posts
  • Last active: Sep 23 2010 04:01 PM
  • Joined: 06 Sep 2010
Any ideas how to call DxgkDdiSetBrightness from AutoHotkey? (more info here)
IOCTL is deprecated in Vista/7 and mostly doesn't work anyway, but this method should be the same which is used in the mobility center.
Thanks.

rcll
  • Members
  • 4 posts
  • Last active: Oct 23 2010 02:58 PM
  • Joined: 20 Oct 2010
Sorry to post in this old thread but I'm also looking for this solution.

The Fn keys on my laptop are signaled at BIOS level or something and seem impossible to remap using the HID DLL method to identify the keys.

Windows Mobility Center has a GUI brightness slider that corresponds to the same function, brightness up/brightness down. Can this be mapped to a hotkey?