Hotkey to Change Laptop Brightness Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
poetofpiano
Posts: 61
Joined: 25 Jan 2016, 14:26

Hotkey to Change Laptop Brightness

12 Aug 2017, 23:23

I have a Dell laptop and am trying to figure out how to set a hotkey in Autohotkey to control the screen brightness that is different from the default brightness hotkeys on my laptop, which don’t register in Autohotkey when I press them. I have researched this to death but cannot find a solution. The most promising post I found was at https://autohotkey.com/boards/viewtopic ... 1&p=126135 which uses the Windows native brightness function to adjust the screen brightness just like I want (I am not interested in using Autohotkey to create a GUI that dims the screen). 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. The following is what the log reads when I try to execute the hotkey to change the brightness:

Code: Select all

222: BS.SetBrightness(-10)  
034: if (increment == 0 && !jump)  
040: if (!forceDifferentScheme ? DllCall(PowerGetActiveScheme, "Ptr", 0, "Ptr*", currSchemeGuid, "UInt") == 0 : DllCall("powrprof\PowerDuplicateScheme", "Ptr", 0, "Ptr", forceDifferentScheme, "Ptr*
077: }
222: Return (0.25)
Any help would be greatly appreciated!
qwerty12
Posts: 468
Joined: 04 Mar 2016, 04:33
Contact:

Re: Hotkey to Change Laptop Brightness  Topic is solved

13 Aug 2017, 05:33

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! :-)
Last edited by qwerty12 on 13 Aug 2017, 20:34, edited 1 time in total.
poetofpiano
Posts: 61
Joined: 25 Jan 2016, 14:26

Re: Hotkey to Change Laptop Brightness

13 Aug 2017, 13:37

Thank you both so much. qwerty12, your suggestion worked perfectly, thank you!
jamesbermudean
Posts: 4
Joined: 06 Oct 2017, 15:27

Re: Hotkey to Change Laptop Brightness

06 Oct 2017, 15:40

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! :-)
Christopher
Posts: 1
Joined: 23 Nov 2020, 01:42

Re: Hotkey to Change Laptop Brightness

13 Dec 2020, 01:07

A simple way to do it.

Code: Select all

; gist.github.com/krrr/3c3f1747480189dbb71f
#,::
  AdjustScreenBrightness(-3)
  Return
  
#.::
  AdjustScreenBrightness(3)
  Return
  
AdjustScreenBrightness(step) {
    service := "winmgmts:{impersonationLevel=impersonate}!\\.\root\WMI"
    monitors := ComObjGet(service).ExecQuery("SELECT * FROM WmiMonitorBrightness WHERE Active=TRUE")
    monMethods := ComObjGet(service).ExecQuery("SELECT * FROM wmiMonitorBrightNessMethods WHERE Active=TRUE")
    minBrightness := 5  ; level below this is identical to this

    for i in monitors {
        curt := i.CurrentBrightness
        break
    }
    if (curt < minBrightness)  ; parenthesis is necessary here
        curt := minBrightness
    toSet := curt + step
    if (toSet > 100)
        return
    if (toSet < minBrightness)
        toSet := minBrightness
        
    

    for i in monMethods {
        i.WmiSetBrightness(1, toSet)
        break
    }
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], ntepa, scriptor2016 and 185 guests