Set laptop brightness & show Win 10's native OSD

Post your working scripts, libraries and tools for AHK v1.1 and older
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
Contact:

Set laptop brightness & show Win 10's native OSD

15 Jan 2017, 12:26

Not particularly impressive considering some of the stuff you can find here, but I actually had a need for something like this, wanting to control my laptop's brightness from my phone using Unified Remote.

On Windows 10, it will set the laptop's monitor brightness and show the brightness OSD present there.

Showing the OSD might be a bit iffy, however:
  • On Windows 10, the OSD window responds to a SHELLHOOK message to show the OSD on demand. However, the window to send said message to doesn't exist until it's created by pressing the brightness/volume buttons (the former only available physically), or if an undocumented function provided by the shell over COM is called. To create the window if needed, this tries the latter first and then falls back to quickly muting/unmuting the volume. I suspect with every new Windows 10 service pack major update, the GUIDs needed to call the COM method will change, like how they did for the IPolicyConfig interface and "IVirtualDesktopManagerInternal". The SID and IID is correct for 14393.693.
  • On Windows 8, I'm hoping the behaviour is the same, but I haven't checked
  • On Windows 7, there is no OSD to speak of
To use, paste the contents of the Gist into your file or save the raw contents of the Gist as something like, say, BrightnessSetter.ahk in a default AutoHotkey library folder. And then do something like this:

Code: Select all

#include <BrightnessSetter> ; if you saved the class as its own file
BrightnessSetter.SetBrightness(-10)
If an own instance of the BrightnessSetter class is created, then it will monitor the AC insertion state. That's optional, however.

There's really only one method that actually does anything, the SetBrightness method. Its parameters:
  • increment - how much to increase or decrease the current brightness by. If jump is set, then increment is considered to be an absolute value
  • jump - sets the brightness directly instead of working relatively with the current brightness value. False by default
  • showOSD - determines if the OSD should be shown. To match the behaviour of the physical brightness keys, BrightnessSetter shows the OSD regardless of whether the brightness was actually changed. True by default
  • autoDcOrAc - set to -1 if you want BrightnessSetter to determine the power source and set the brightness for the active power source, 0 if you want the brightness value for when battery power is active to be changed, and 1 for the brightness value when a charger is plugged in. -1 by default
  • forceDifferentScheme - by default, BrightnessSetter works on the active power plan. If you want the brightness for a non-active power plan to be set, you can pass a pointer to the appropriate GUID structure for it. Linear Spoon has an excellent post here on using PowerEnumerate to get all the power plans on the system along with their GUIDs. 0 by default to force using the active scheme
Credits:
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Set laptop brightness & show Win 10's native OSD

27 May 2017, 15:20

Cheers, for this it's really nice.

I use Windows 7, and for some reason GetModuleHandle wasn't working with powrprof.dll, however I rewrote some code without GetModuleHandle and everything was working fine. (I tried x64 and x32 AHK, and I did have Wow64 file system redirection turned off.)

Btw is that what f.lux uses? How do you change the RGB? E.g. reduce the blue?

I used a script with partially transparent black windows to control brightness before(/now), although that of course would darken any printscreens, unless I turned it off temporarily (i.e. a camera flash effect that I wrote), this should give me a much better solution.

Although, this does not affect my television, only my laptop, I think f.lux affects both.

Anyhow, I'll post my working code, and my test attempts:

Code: Select all

q:: ;get/set AC/DC brightness
DllCall("powrprof\PowerGetActiveScheme", "Ptr", 0, "Ptr*", currSchemeGuid, "UInt")
MsgBox, % currSchemeGuid

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")

schemeGuid := currSchemeGuid

DllCall("powrprof\PowerReadDCValueIndex", "Ptr", 0, "Ptr", schemeGuid, "Ptr", &GUID_VIDEO_SUBGROUP__, "Ptr", &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, "UInt*", currBrightness, "UInt")
MsgBox, % currBrightness ;40

DllCall("powrprof\PowerReadACValueIndex", "Ptr", 0, "Ptr", schemeGuid, "Ptr", &GUID_VIDEO_SUBGROUP__, "Ptr", &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, "UInt*", currBrightness, "UInt")
MsgBox, % currBrightness ;46

currBrightness := 46
DllCall("powrprof\PowerWriteACValueIndex", "Ptr", 0, "Ptr", currSchemeGuid, "Ptr", &GUID_VIDEO_SUBGROUP__, "Ptr", &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, "UInt", currBrightness, "UInt")
;DllCall("powrprof\PowerWriteDCValueIndex", "Ptr", 0, "Ptr", currSchemeGuid, "Ptr", &GUID_VIDEO_SUBGROUP__, "Ptr", &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, "UInt", currBrightness, "UInt")
DllCall("powrprof\PowerSetActiveScheme", "Ptr", 0, "Ptr", currSchemeGuid, "UInt")
return

;==================================================

;q:: ;test BrightnessSetter (didn't work)
MsgBox, % DllCall("GetModuleHandle", "Str", "powrprof.dll", "Ptr")
MsgBox, % DllCall("GetModuleHandle", "Str", "C:\Windows\System32\powrprof.dll", "Ptr")
;MsgBox, % A_LastError ;126 ;The specified module could not be found.

PowerGetActiveScheme := DllCall("GetProcAddress", "Ptr", DllCall("GetModuleHandle", "Str", "powrprof.dll", "Ptr"), "AStr", "PowerGetActiveScheme", "Ptr")
MsgBox, % PowerGetActiveScheme
MsgBox, % DllCall(PowerGetActiveScheme, "Ptr", 0, "Ptr*", currSchemeGuid, "UInt")
MsgBox, % currSchemeGuid

BrightnessSetter := new BrightnessSetter
MsgBox, % BrightnessSetter.GetMaxBrightness()
MsgBox, % BrightnessSetter.GetMinBrightness()
MsgBox, % BrightnessSetter._AC
schemeGuid := currSchemeGuid
AC := BrightnessSetter._AC
MsgBox, % BrightnessSetter._GetCurrentBrightness(schemeGuid, AC)

;BrightnessSetter.SetBrightness(-10) ;relative
;BrightnessSetter.SetBrightness(50, 1) ;absolute
return

;==================================================

;class BrightnessSetter {
;	; qwerty12 - 15/01/17
;	static _WM_POWERBROADCAST := 0x218, _osdHwnd := 0
;...
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
Contact:

Re: Set laptop brightness & show Win 10's native OSD

27 May 2017, 15:40

jeeswg wrote:I use Windows 7, and for some reason GetModuleHandle wasn't working with powrprof.dll, however I rewrote some code without GetModuleHandle and everything was working fine. (I tried x64 and x32 AHK, and I did have Wow64 file system redirection turned off.)
That's odd. I know PowerApplySettingChanges is undocumented and doesn't exist in WIndows 7, but the script should (read: is meant to) fall back to PowerSetActiveScheme... If I somehow get Windows 7 installed in EFI mode, I'll use your script and try and see what I'm doing wrong. Thanks, jeeswg.
Btw is that what f.lux uses? How do you change the RGB? E.g. reduce the blue?
AFAIK, that's gamma/colour correction territory. jNizM's https://github.com/jNizM/Class_Monitor will allow you to do just that.

Non-AHK open source f.lux alternatives:

https://github.com/jonls/redshift
https://github.com/Tyrrrz/LightBulb
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Set laptop brightness & show Win 10's native OSD

27 May 2017, 15:54

The problem I'm having is with GetModuleHandle, which may have little or nothing do to with this script as a whole, in case you had any ideas why it wasn't working. Clearly though when I called the dll directly it worked.

I tested PowerSetActiveScheme and it worked, I didn't try PowerApplySettingChanges. [EDIT:] Out of interest, I just tested PowerApplySettingChanges, it didn't work, as expected.

Thanks very much re. the 3 f.lux links.
Last edited by jeeswg on 27 May 2017, 16:04, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
Contact:

Re: Set laptop brightness & show Win 10's native OSD

27 May 2017, 16:01

jeeswg wrote:The problem I'm having is with GetModuleHandle, which may have little or nothing do to with this script as a whole, in case you had any ideas why it wasn't working. Clearly though when I called the dll directly it worked.
Sorry, I get what you mean now. I guess some other DLL loaded by Windows automatically loads powrprof.dll on (my) Windows 10 system(s), which is why I assumed using GetModuleHandle would be universally OK. Using LoadLibrary should sort it. I'll make the changes soon.
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Set laptop brightness & show Win 10's native OSD

27 May 2017, 16:06

Ahh, GetModuleHandle / LoadLibrary. Bit embarrassing, I guess I was kinda confused by the two, because I don't use them that often, yes that sounds likely. I thought GetModuleHandle was loading the module, yeah getting the module (handle) v. loading the library.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
jamesbermudean
Posts: 4
Joined: 06 Oct 2017, 15:27

Re: Set laptop brightness & show Win 10's native OSD

11 Oct 2017, 15:03

Hello, I am newbie here, but I have been using AutoHotkey since some years ago.
I was looking for a way to control my laptop's brightness, and your script seems to be the solution.
I am getting an error (Call to nonexistent function), and I have read that powrprof.dll is not loaded, but I don't know how to load it or fix it.
Any help would be much appreciated (I'm using Windows 10, x64, updated to last version).
Thank you so much :)
qwerty12 wrote:
poetofpiano wrote:But for some reason that script doesn’t work for me. I followed the instructions for that script at https://www.reddit.com/r/AutoHotkey/com ... ss_script/ and it just doesn’t work.
Replace the copied class with this one (or just save it as BrightnessSetter.ahk and do the usual library thing if you'd prefer):
The version you have is an old one, where it assumes powrprof.dll is always loaded (thanks to jeeswg, I found out it wasn't)...

EDIT: You're welcome, poetofpiano! Thanks for being the fourth person to use the script! :-)
pneumatic
Posts: 338
Joined: 05 Dec 2016, 01:51

Re: Set laptop brightness & show Win 10's native OSD

23 Mar 2018, 12:29

Thank you qwerty12 for taking the time to make this class.

I would like to add a couple of extra conditions to it:

1. Detect if the user's system supports this method of brightness control in the first place, and if not, do nothing. Should I simply modify line 48 as follows?

Code: Select all

if (jump && BrightnessSetter._GetCurrentBrightness(currSchemeGuid, AC, currBrightness := 0))
2. If the current brightness is already set to the requested value, do nothing. Should I modify line 52 as follows?

Code: Select all

if (jump || !((currBrightness == maxBrightness && increment > 0) || (currBrightness == minBrightness && increment < minBrightness) || (currBrightness == jump)))
Thanks
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
Contact:

Re: Set laptop brightness & show Win 10's native OSD

23 Mar 2018, 20:04

jamesbermudean wrote:Hello, I am newbie here, but I have been using AutoHotkey since some years ago.
I was looking for a way to control my laptop's brightness, and your script seems to be the solution.
I am getting an error (Call to nonexistent function), and I have read that powrprof.dll is not loaded, but I don't know how to load it or fix it.
Any help would be much appreciated (I'm using Windows 10, x64, updated to last version).
Thank you so much :)
I doubt you have a need for this any more (and I am sorry for the fact I am getting back to you now) but while I happily admit my sentences and explanations can suck, honestly the most basic instructions would be "paste the contents of the gist into a new AHK script at the end, add something like BrightnessSetter.SetBrightness(-10) at the top and run the script to see if this actually works for you" (of course, the brightness should be quite high in the first place to see the result!)

If it does, just tack your preferred hotkey on
pneumatic wrote:1. Detect if the user's system supports this method of brightness control in the first place, and if not, do nothing. Should I simply modify line 48 as follows?
The Power control panel does this to find out if the power management subsystem is running on a device where it can change the brightness:

Code: Select all

VarSetCapacity(SystemPowerCapabilities, 76)
if (!DllCall("powrprof\GetPwrCapabilities", "Ptr", &SystemPowerCapabilities) || !NumGet(SystemPowerCapabilities, 10, "UChar")) ; VideoDim[Not]Present
	return
2. If the current brightness is already set to the requested value, do nothing. Should I modify line 52 as follows?
Personally, I would keep that if statement the same (the increment stuff that follows makes sure the new brightness value is within bounds for jump and non-jump functionality) but make the following changes:

if (jump || BrightnessSetter._GetCurrentBrightness(currSchemeGuid, AC, currBrightness)) {

into

Code: Select all

if (BrightnessSetter._GetCurrentBrightness(currSchemeGuid, AC, currBrightness)) {
(short-circuit evaluation will prevent the current brightness value from being obtained if jump == True)

and just turn

if (DllCall(AC ? PowerWriteACValueIndex : PowerWriteDCValueIndex, "Ptr", 0, "Ptr", currSchemeGuid, "Ptr", BrightnessSetter._GUID_VIDEO_SUBGROUP(), "Ptr", BrightnessSetter._GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS(), "UInt", increment, "UInt") == 0) {

into

Code: Select all

if (increment != currBrightness && DllCall(AC ? PowerWriteACValueIndex : PowerWriteDCValueIndex, "Ptr", 0, "Ptr", currSchemeGuid, "Ptr", BrightnessSetter._GUID_VIDEO_SUBGROUP(), "Ptr", BrightnessSetter._GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS(), "UInt", increment, "UInt") == 0) {
(and move the if showOSD block into the PowerWriteACValueIndex one to stop the brightness OSD from showing even if the brightness wasn't changed)

AHK has had MIN/MAX functions now for a while, which could make that function a bit smaller but I'm too tired for that now. Though I did fix the broken jump functionality, which I could swear it did work when I put out the script, and a small possible memory leak)
Helgef wrote:cool, works fine on my win7 laptop, thanks for sharing :clap:.

Cheers.
Thanks, I only tried this on 10 :-)
Last edited by qwerty12 on 25 Mar 2018, 12:56, edited 1 time in total.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Set laptop brightness & show Win 10's native OSD

25 Mar 2018, 07:12

cool, works fine on my win7 laptop, thanks for sharing :clap:.

Cheers.
crumbl3d
Posts: 3
Joined: 23 Jun 2018, 17:01
Contact:

Re: Set laptop brightness & show Win 10's native OSD

25 Jun 2018, 15:56

This does not seem to work with x86 AHK at least on x64 OS. I am making a script that could eventually be compiled to both x86 and x64 but while x64 runs fine x86 just shows the OSD and nothing changes.
User avatar
berban
Posts: 97
Joined: 14 Apr 2014, 03:20

Re: Set laptop brightness & show Win 10's native OSD

24 Feb 2019, 20:52

This is so helpful! I wish I had found it long ago. Thanks!!
haijie1223
Posts: 1
Joined: 20 Jul 2019, 22:19

Re: Set laptop brightness & show Win 10's native OSD

20 Jul 2019, 22:29

he fuction _RealiseOSDWindowIfNeeded ,Use the com interface,Where to find this information?
Mostafa_a
Posts: 1
Joined: 07 Feb 2021, 03:21

Re: Set laptop brightness & show Win 10's native OSD

07 Feb 2021, 03:34

I want to share another code for increment/decrement the laptop monitor brightness.

Code: Select all

; ----------- Change laptop brightness by an arbitrary step. --------------
; This is an AutoHotKey for increment/decrement the Laptop Monitor Brighnes (Dim Screen) by an arbitary step.
; "CapsLock + Right/Left rrow" Keys is set for changing the screen Dim.
; I tested it on Windows 10. + I'm sure it works on windows 7, too. ---
CapsLock & Right:: 
	DimStep = 5
	; ----------------------------
	DllCall("powrprof\PowerGetActiveScheme", "Ptr", 0, "Ptr*", currSchemeGuid, "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")
	schemeGuid := currSchemeGuid
	; ----------------------------
	powerstatusValue := powerstatus()
	if (powerstatusValue = 1) {
		DllCall("powrprof\PowerReadACValueIndex", "Ptr", 0, "Ptr", schemeGuid, "Ptr", &GUID_VIDEO_SUBGROUP__, "Ptr", &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, "UInt*", currBrightnessAC, "UInt")
		; MsgBox, currBrightnessAC = %currBrightnessAC%
		currBrightness := currBrightnessAC + DimStep
		DllCall("powrprof\PowerWriteACValueIndex", "Ptr", 0, "Ptr", currSchemeGuid, "Ptr", &GUID_VIDEO_SUBGROUP__, "Ptr", &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, "UInt", currBrightness, "UInt")
	}
	else {
		DllCall("powrprof\PowerReadDCValueIndex", "Ptr", 0, "Ptr", currSchemeGuid, "Ptr", &GUID_VIDEO_SUBGROUP__, "Ptr", &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, "UInt*", currBrightnessDC, "UInt")
		; MsgBox, currBrightnessDC = %currBrightnessDC%
		currBrightness := currBrightnessDC + DimStep
		DllCall("powrprof\PowerWriteDCValueIndex", "Ptr", 0, "Ptr", currSchemeGuid, "Ptr", &GUID_VIDEO_SUBGROUP__, "Ptr", &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, "UInt", currBrightness, "UInt")
	}
	DllCall("powrprof\PowerSetActiveScheme", "Ptr", 0, "Ptr", currSchemeGuid, "UInt")
return


CapsLock & Left:: 
	DimStep = 5
	; ----------------------------
	DllCall("powrprof\PowerGetActiveScheme", "Ptr", 0, "Ptr*", currSchemeGuid, "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")
	schemeGuid := currSchemeGuid
	; ----------------------------
	powerstatusValue := powerstatus()
	if (powerstatusValue = 1) {
		DllCall("powrprof\PowerReadACValueIndex", "Ptr", 0, "Ptr", schemeGuid, "Ptr", &GUID_VIDEO_SUBGROUP__, "Ptr", &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, "UInt*", currBrightnessAC, "UInt")
		; MsgBox, currBrightnessAC = %currBrightnessAC%
		currBrightness := currBrightnessAC - DimStep
		DllCall("powrprof\PowerWriteACValueIndex", "Ptr", 0, "Ptr", currSchemeGuid, "Ptr", &GUID_VIDEO_SUBGROUP__, "Ptr", &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, "UInt", currBrightness, "UInt")
	}
	else {
		DllCall("powrprof\PowerReadDCValueIndex", "Ptr", 0, "Ptr", currSchemeGuid, "Ptr", &GUID_VIDEO_SUBGROUP__, "Ptr", &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, "UInt*", currBrightnessDC, "UInt")
		; MsgBox, currBrightnessDC = %currBrightnessDC%
		currBrightness := currBrightnessDC - DimStep
		DllCall("powrprof\PowerWriteDCValueIndex", "Ptr", 0, "Ptr", currSchemeGuid, "Ptr", &GUID_VIDEO_SUBGROUP__, "Ptr", &GUID_DEVICE_POWER_POLICY_VIDEO_BRIGHTNESS__, "UInt", currBrightness, "UInt")
	}
	DllCall("powrprof\PowerSetActiveScheme", "Ptr", 0, "Ptr", currSchemeGuid, "UInt")
return


; ----  sub functions --------
powerstatus() {
	VarSetCapacity(powerstatus, 1+1+1+1+4+4)
	success := DllCall("kernel32.dll\GetSystemPowerStatus", "uint", &powerstatus)

	acLineStatus:=ReadInteger(&powerstatus,0,1,false)
	batteryFlag:=ReadInteger(&powerstatus,1,1,false)
	batteryLifePercent:=ReadInteger(&powerstatus,2,1,false)
	batteryLifeTime:=ReadInteger(&powerstatus,4,4,false)
	batteryFullLifeTime:=ReadInteger(&powerstatus,8,4,false)

	output=AC Status: %acLineStatus%`nBattery Flag: %batteryFlag%`nBattery Life (percent): %batteryLifePercent%`nBattery Life (time): %batteryLifeTime%`nBattery Life (full time): %batteryFullLifeTime%
	; MsgBox, %output%
	return acLineStatus
}
ReadInteger( p_address, p_offset, p_size, p_hex=true )
{
  value = 0
  old_FormatInteger := a_FormatInteger
  if ( p_hex )
	SetFormat, integer, hex
  else
	SetFormat, integer, dec
  loop, %p_size%
	value := value+( *( ( p_address+p_offset )+( a_Index-1 ) ) << ( 8* ( a_Index-1 ) ) )
  SetFormat, integer, %old_FormatInteger%
  return, value
}
; -------------------------- End -------------------------
iseahound
Posts: 1434
Joined: 13 Aug 2016, 21:04
Contact:

Re: Set laptop brightness & show Win 10's native OSD

07 Feb 2021, 12:29

As crumbl3d says, this doesn't work when using AutoHotkey 32-bit on a 64-bit OS. The OSD displays, but the brightness refuses to move up or down. Thanks for making this script!
kenji
Posts: 16
Joined: 08 Nov 2021, 03:15

Re: Set laptop brightness & show Win 10's native OSD

07 Dec 2021, 04:06

crumbl3d wrote:
25 Jun 2018, 15:56
This does not seem to work with x86 AHK at least on x64 OS. I am making a script that could eventually be compiled to both x86 and x64 but while x64 runs fine x86 just shows the OSD and nothing changes.
did you found any solution ?
i am on x86 AHK and on x64 OS..

the thing i found if i lauch the script using vscode having the plugin autohotkey plus plus it works but why ?

you have any solution. i tried other method to set brightness but they seem to be slow to activate and don't show OSD .
gregster
Posts: 8916
Joined: 30 Sep 2013, 06:48

Re: Set laptop brightness & show Win 10's native OSD

07 Dec 2021, 04:09

kenji wrote:
07 Dec 2021, 04:06
the thing i found if i lauch the script using vscode having the plugin autohotkey plus plus it works but why ?
Could be a permissions issue. Try to run your script 'as admin'.
kenji
Posts: 16
Joined: 08 Nov 2021, 03:15

Re: Set laptop brightness & show Win 10's native OSD

07 Dec 2021, 08:47

gregster wrote:
07 Dec 2021, 04:09
kenji wrote:
07 Dec 2021, 04:06
the thing i found if i lauch the script using vscode having the plugin autohotkey plus plus it works but why ?
Could be a permissions issue. Try to run your script 'as admin'.
VScode was running it with 64 autohotkey and explorer was running it with 32 bit one.. i simply switch my autohotkey to 64 version. now it works.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: gwarble and 107 guests