Change screen brightness using mouse wheel

Share your favorite FastKeys commands
User avatar
gustms
Posts: 133
Joined: Sep 26th, ’14, 21:32
Location: USA

Post by gustms » Sep 26th, ’14, 23:02

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.
User avatar
Marko
Posts: 1718
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Sep 27th, ’14, 07:24

Great idea, thanks, I'm sure it is possible. I'll take a look. :D
User avatar
gustms
Posts: 133
Joined: Sep 26th, ’14, 21:32
Location: USA

Post by gustms » Sep 27th, ’14, 15:43

Thank you. Looking forward to it!
User avatar
Marko
Posts: 1718
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Sep 27th, ’14, 22:50

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
gustms
Posts: 133
Joined: Sep 26th, ’14, 21:32
Location: USA

Post by gustms » Sep 28th, ’14, 22:41

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.
User avatar
Marko
Posts: 1718
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Oct 1st, ’14, 19:04

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
gustms
Posts: 133
Joined: Sep 26th, ’14, 21:32
Location: USA

Post by gustms » Oct 4th, ’14, 16:22

Thank you!
User avatar
Gryzor
Posts: 62
Joined: Nov 13th, ’14, 19:25

Post by Gryzor » Nov 14th, ’14, 19:24

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
Gryzor
Posts: 62
Joined: Nov 13th, ’14, 19:25

Post by Gryzor » Nov 14th, ’14, 19:24

...and here's the link: http://www.autohotkey.com/board/topic/8 ... rightness/

Oh, and also this: http://www.autohotkey.com/board/topic/5 ... e-control/
User avatar
Marko
Posts: 1718
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Nov 16th, ’14, 00:25

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. ;)
Post Reply