Change screen brightness using mouse wheel

Share your favorite FastKeys commands
User avatar
Posts: 77
Joined: Fri Sep 26, 2014 8:32 pm

Change screen brightness using mouse wheel

PostPosted by gustms » Fri Sep 26, 2014 10:02 pm

Hello there, just bought this excellent software.

I really like the volume control using mouse wheel option, on right edge of screen, and thought, why not an option to change screen brightness at the left edge of the screen, using the mouse wheel as well? I often change my screen birghtness depending on the time of the day, and the room's lightining, and this would help a lot.

Any way to do this using a command or something?

Thanks in advance.

Site Admin
User avatar
Posts: 628
Joined: Sat Mar 02, 2013 9:02 pm

Re: Change screen brightness using mouse wheel

PostPosted by Marko » Sat Sep 27, 2014 6:24 am

Great idea, thanks, I'm sure it is possible. I'll take a look. :D

User avatar
Posts: 77
Joined: Fri Sep 26, 2014 8:32 pm

Re: Change screen brightness using mouse wheel

PostPosted by gustms » Sat Sep 27, 2014 2:43 pm

Thank you. Looking forward to it!

Site Admin
User avatar
Posts: 628
Joined: Sat Mar 02, 2013 9:02 pm

Re: Change screen brightness using mouse wheel

PostPosted by Marko » Sat Sep 27, 2014 9:50 pm

The easiest would be just to use the command below (found a function on Autohotkey forum). You can put it in the start menu, define shortcuts etc. for your favorite brightness levels. Change the first line to required brightness level.

Code: Select all
br:=60  ;Brightness: 0=Darkest, 255=Brightest, 128 Normal
VarSetCapacity(gr, 512*3)
Loop, 256
{
   If  (nValue:=(br+128)*(A_Index-1))>65535
        nValue:=65535
   NumPut(nValue, gr,      2*(A_Index-1), "Ushort")
   NumPut(nValue, gr,  512+2*(A_Index-1), "Ushort")
   NumPut(nValue, gr, 1024+2*(A_Index-1), "Ushort")
}
hDC := DllCall("GetDC", "Uint", 0)
DllCall("SetDeviceGammaRamp", "Uint", hDC, "Uint", &gr)
DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)


I may prepare more elaborate commands when I get time.

User avatar
Posts: 77
Joined: Fri Sep 26, 2014 8:32 pm

Re: Change screen brightness using mouse wheel

PostPosted by gustms » Sun Sep 28, 2014 9:41 pm

Thank you! Added it to Start Menu. Seems like it doesn't exactly use Windows brightness controls, but it works!

Still, a feature like the current volume control with mouse wheel would be the best, if that's possible.

Thanks again.

Site Admin
User avatar
Posts: 628
Joined: Sat Mar 02, 2013 9:02 pm

Re: Change screen brightness using mouse wheel

PostPosted by Marko » Wed Oct 01, 2014 6:04 pm

Here are the updated scripts:

1. Change screen brightness up/down
Shortcut: ^WheelUp (up - set First line to V=3)
Shortcut: ^WheelDown (down - set first line to V=-3)
Type: Command
Code: Select all
V:=3  ;positive-step up, negative-step down

#MaxHotkeysPerInterval 10000
VarSetCapacity(GR,1536,0)
DllCall("GetDeviceGammaRamp", UInt,hDC := DllCall("GetDC", UInt,0), UInt,&GR)
Current:=NumGet(GR, 2, "UShort") - 128, DllCall("ReleaseDC", UInt,0, UInt,hDC)
Br:=(Br := Current + V) > 255 ? 255 : Br < 0 ? 0 : Br

Loop, % VarSetCapacity(GR,1536)/6
NumPut((n := (Br+128)*(A_Index-1)) > 65535 ? 65535 : n, GR, 2*(A_Index-1), "UShort")
DllCall("RtlMoveMemory", UInt,&GR+512, UInt,&GR, UInt,512)
DllCall("RtlMoveMemory", UInt,&GR+1024, UInt,&GR, UInt,512)
DllCall("SetDeviceGammaRamp", UInt,hDC := DllCall("GetDC", UInt,0), UInt,&GR)
, DllCall("ReleaseDC", UInt,0, UInt,hDC)


2. Set Screen Brightness
Shortcut: Alt-X
Type: Command
Set first line to Br:=brightness level between 0 and 255: 0=Darkest, 255=Brightest, 128 Normal
Code: Select all
Br=128  ;0-255, 128=normal

Loop, % VarSetCapacity(GR,1536)/6
NumPut((n := (Br+128)*(A_Index-1)) > 65535 ? 65535 : n, GR, 2*(A_Index-1), "UShort")
DllCall("RtlMoveMemory", UInt,&GR+512, UInt,&GR, UInt,512)
DllCall("RtlMoveMemory", UInt,&GR+1024, UInt,&GR, UInt,512)
DllCall("SetDeviceGammaRamp", UInt,hDC := DllCall("GetDC", UInt,0), UInt,&GR)
, DllCall("ReleaseDC", UInt,0, UInt,hDC)

User avatar
Posts: 77
Joined: Fri Sep 26, 2014 8:32 pm

Re: Change screen brightness using mouse wheel

PostPosted by gustms » Sat Oct 04, 2014 3:22 pm

Thank you!

User avatar
Posts: 50
Joined: Thu Nov 13, 2014 7:25 pm
Location: Athens, Greece

Re: Change screen brightness using mouse wheel

PostPosted by Gryzor » Fri Nov 14, 2014 7:24 pm

I would love for this scrip to work for my laptop since Sony has screwed up royally and the driver that activates the brightness keys cannot even be installed. However, the script doesn't really change brightness, but gamma. Of course this is readily apparent since it uses xxxDeviceGammaRamp.

I found this: (link in the following post because this is my first one) but I'm not really conversant with HK...

User avatar
Posts: 50
Joined: Thu Nov 13, 2014 7:25 pm
Location: Athens, Greece

Re: Change screen brightness using mouse wheel

PostPosted by Gryzor » Fri Nov 14, 2014 7:24 pm


Site Admin
User avatar
Posts: 628
Joined: Sat Mar 02, 2013 9:02 pm

Re: Change screen brightness using mouse wheel

PostPosted by Marko » Sun Nov 16, 2014 12:25 am

Hi Gryzor and welcome to the forum. I tried the scripts in the links but unfortunately none of them work on my computer, maybe they are laptop or OS specific.

You can copy any of the AutoHotkey scripts and paste it to the txt file. Save the file as FileName.ahk to the FastKeys scripts folder. Then you can run it from any module - select Type: Script and press "Open" button to select the script.

Please let me know if you find something which works for you. If you have any question, just ask. ;)

Next

Return to User Commands and Scripts

Who is online

Users browsing this forum: No registered users and 1 guest