AutoHotkey Community

It is currently May 27th, 2012, 1:28 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: February 7th, 2011, 5:05 am 
Offline

Joined: September 20th, 2010, 6:51 am
Posts: 4
Location: Northern California
Use Brightness Console App, the underlying code to the "Display Brightness Vista Gadget":

http://edgylogic.com/projects/display-brightness-vista-gadget/

Then something like:
#^1::Run C:\Users\Loren\Documents\BrightnessConsoleApp\Brt.exe 10
#^2::Run C:\Users\Loren\Documents\BrightnessConsoleApp\Brt.exe 20
#^3::Run C:\Users\Loren\Documents\BrightnessConsoleApp\Brt.exe 30

Works great!

Now - how to turn the backlight completely off? Brightness 0 for this routine is still 10%, not off.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 19th, 2011, 6:35 pm 
Offline

Joined: April 19th, 2011, 6:28 pm
Posts: 1
I've done something similar with DisplayBrightnessConsole. I wanted control f6 and f7 to raise and lower the brightness. I found some other scripts around that seemed to do the job, but it turned out they weren't lowering or raising the backlight, just somehow dimming the graphics!

Anyways, you need to get DisplayBrightnessConsole from the previous post, as well as xargs (available @ http://gnuwin32.sourceforge.net/packages/findutils.htm)

Put the xargs, DisplayBrignthessConsole.exe and the xargs dependency dlls libiconv2 and libintl3 in the same folder. In that folder i created 2 bat files:

screendown.bat has the following line
@DisplayBrightnessConsole.exe | xargs cmd /c set /a -10+ | xargs DisplayBrightnessConsole

screenup.bat has the following line
@DisplayBrightnessConsole.exe | xargs cmd /c set /a 10+ | xargs DisplayBrightnessConsole

Then i made a .AHK to call those bat files:
^F7::Run screenup.bat,,Hide
^F6::Run screendown.bat,,Hide

Seems to work pretty well. It's a little slow, but i suppose i can live with that.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 25th, 2011, 7:44 am 
temp01 wrote:
Does this work (I don't have an LCD monitor to test)? If not, what does the msgbox show?
Code:
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))

I just wanted to let everyone know that this worked perfectly for me. In fact with a little tweaking (and use of IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS and NumGet), I was able to manually add or subtract brightness like so many laptops do with extra Fn key shortcuts. My specific use here was for remapping the Apple Wireless Keyboard following this tutorial (by Veil and Leon): http://www.autohotkey.net/~daonlyfreez/tutorials/3p/Veil/fnkey.htm. I wanted to add the brightness controls using F1 and F2, and because I'm running Vista on a Lenovo Laptop, the Fn key and Eject did not work. So far my customizing is working quite well, and I know I've read a lot of other threads where users have struggled with the Fn key. This tutorial is the way to go, in fact when compiling it's made even easier by using FileInstall to include the AutohotkeyRemoteControl.dll inside the .exe, so all you have is one small app to run! Thanks a bunch guys.


Report this post
Top
  
Reply with quote  
PostPosted: August 25th, 2011, 11:33 pm 
Offline

Joined: August 14th, 2011, 8:31 pm
Posts: 69
Location: Nova Scotia, Canada
AWK Programmer wrote:
temp01 wrote:
Does this work (I don't have an LCD monitor to test)? If not, what does the msgbox show?
Code:
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))

I just wanted to let everyone know that this worked perfectly for me. In fact with a little tweaking (and use of IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS and NumGet), I was able to manually add or subtract brightness like so many laptops do with extra Fn key shortcuts. My specific use here was for remapping the Apple Wireless Keyboard following this tutorial (by Veil and Leon): http://www.autohotkey.net/~daonlyfreez/tutorials/3p/Veil/fnkey.htm. I wanted to add the brightness controls using F1 and F2, and because I'm running Vista on a Lenovo Laptop, the Fn key and Eject did not work. So far my customizing is working quite well, and I know I've read a lot of other threads where users have struggled with the Fn key. This tutorial is the way to go, in fact when compiling it's made even easier by using FileInstall to include the AutohotkeyRemoteControl.dll inside the .exe, so all you have is one small app to run! Thanks a bunch guys.





I optomised it a bit. This runs perfect for me.

Code:
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
   . 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)
   DllCall("CloseHandle", UInt, hLCD)
}

_________________
ImageImage


Twitter: http://twitter.com/NictraSavios
Tumblr: http://nictrasavios.tumblr.com


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Universal script
PostPosted: October 30th, 2011, 8:51 am 
Offline

Joined: October 30th, 2011, 8:23 am
Posts: 2
The code posted didn't work on my ASUS laptop but I liked jmez and LorenAmelangs idea of using DisplayBrightnessConsole. The only problem with their scripts is that they adjust the brightness at a specific interval. Since everyone's laptop is going to have a different increment / amount of brightness levels it doesn't work very well.

Here is a universal script which uses DisplayBrightnessLevels.exe to read and save the available levels and then change the current level up or down using two hotkeys. As a bonus I included nircmd.exe to turn on and off the screen using a third hotkey.

Just put the files in the same directory as the script and run or compile. Or use my pre-compiled version (brightness1.exe) that includes all the files already. I used F5 (down), F6 (Up), and F7(off/on) because that is what my keyboard shows for the fn commands.

Code:
SetWorkingDir %A_ScriptDir%
FileInstall, DisplayBrightnessConsole.exe, DisplayBrightnessConsole.exe
FileInstall, nircmd.exe, nircmd.exe
#NoTrayIcon
#SingleInstance
#MaxThreads 2
#MaxThreadsBuffer On
SetBatchLines, 10ms
#InstallKeybdHook

IfNotExist, levels.txt
{
   lvlcount = 0
   RunWait %comspec% /c "(DisplayBrightnessConsole.exe -getlevels)>levels.txt",,Hide
}
loop, read, levels.txt
{
   lvl%A_Index% := A_LoopReadLine
   lvlcount += 1
}
maxlvl := lvl%lvlcount%
status=0
RunWait %comspec% /c DisplayBrightnessConsole>current.txt,,Hide
FileReadLine, currentlvl, current.txt, 1

F5::
if currentlvl = %lvl1%
{
   return
}
loop , %lvlcount%
{
   looplvl := lvl%A_Index%
   if currentlvl = %looplvl%
   {
      newcount := A_Index-1
      newlvl := lvl%newcount%
      RunWait %comspec% /c DisplayBrightnessConsole %newlvl%,,Hide
      break
   }
}
RunWait %comspec% /c DisplayBrightnessConsole>current.txt,,Hide
FileReadLine, currentlvl, current.txt, 1
return

F6::
if currentlvl = %maxlvl%
{   
   return
}
loop , %lvlcount%
{
   looplvl := lvl%A_Index%
   if currentlvl = %looplvl%
   {
      newcount := A_Index+1
      newlvl := lvl%newcount%
      RunWait %comspec% /c DisplayBrightnessConsole %newlvl%,,Hide
      break
   }
}
RunWait %comspec% /c DisplayBrightnessConsole>current.txt,,Hide
FileReadLine, currentlvl, current.txt, 1
return

F7::
if (status=0)
{
   Run %ComSpec% /c "nircmd.exe monitor off",,Hide
   status=1
   sleep 1000
} else {
   MouseMove 1,1,,R
   status=0
}
return


Files:
http://www.mediafire.com/?cmswa52v5y18m

Credits:
http://edgylogic.com/projects/display-b ... ta-gadget/
http://www.nirsoft.net/utils/nircmd.html[/code]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 4th, 2011, 6:32 am 
aaronbaird1... I've been looking for a script like yours for years! The only problem is that it's a little slow(which I can live with) and it pops up an alert that says "lvlcount 11" when I run the script. Any thoughts on how to fix that?

Again... thank you sooooooooooo much for the great script!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 4th, 2011, 7:28 am 
ACTUALLY... I just put the brightness1.ahk, levels, and DisplayBrightnessDisplay files in my Startup folder but it causes the levels and current files to open whenever I restart Windows. Any idea on how to keep them from opening?


Report this post
Top
  
Reply with quote  
 Post subject: Version 2!
PostPosted: December 5th, 2011, 2:25 pm 
Offline

Joined: October 30th, 2011, 8:23 am
Posts: 2
jeremetron wrote:
ACTUALLY... I just put the brightness1.ahk, levels, and DisplayBrightnessDisplay files in my Startup folder but it causes the levels and current files to open whenever I restart Windows. Any idea on how to keep them from opening?


put the files somewhere else and place a shortcut to brightnes1.ahk in your startup folder.


Version 2
Whats new:

•greatly improved speed & stability (@jeremetron you will not have that error anymore). I wasn't closing my loops correctly and it was causing all sorts of problems. Still learning :oops:

•if you hold alt before pressing the hotkey, it will function as normal.



Code:
SetWorkingDir %A_ScriptDir%
FileInstall, DisplayBrightnessConsole.exe, DisplayBrightnessConsole.exe
FileInstall, nircmd.exe, nircmd.exe
#NoTrayIcon
#InstallKeybdHook
SetBatchLines, 10ms
SetTimer, LabelKill, 120000

IfNotExist, levels.txt
{
   lvlcount = 0
   RunWait %comspec% /c "(DisplayBrightnessConsole.exe -getlevels)>levels.txt",,Hide
}
loop, read, levels.txt
{
   lvl%A_Index% := A_LoopReadLine
   lvlcount += 1
}
maxlvl := lvl%lvlcount%
RunWait %comspec% /c DisplayBrightnessConsole>current.txt,,Hide
FileReadLine, currentlvl, current.txt, 1

#MaxThreadsBuffer On
*F5::
Critical
GetKeyState, state, Alt
if (state = "D")
{
   SendInput, {F5}
   Exit
}
if currentlvl = %lvl1%
{
   Exit
}
loop , %lvlcount%
{
   looplvl := lvl%A_Index%
   if currentlvl = %looplvl%
   {
      newcount := A_Index-1
      newlvl := lvl%newcount%
      RunWait %comspec% /c DisplayBrightnessConsole %newlvl%,,Hide
      break
   }
}
RunWait %comspec% /c DisplayBrightnessConsole>current.txt,,Hide
FileReadLine, currentlvl, current.txt, 1
return

*F6::
Critical
GetKeyState, state, Alt
if (state = "D")
{
   SendInput, {F6}
   Exit
}
if currentlvl = %maxlvl%
{   
   Exit
}
loop , %lvlcount%
{
   looplvl := lvl%A_Index%
   if currentlvl = %looplvl%
   {
      newcount := A_Index+1
      newlvl := lvl%newcount%
      RunWait %comspec% /c DisplayBrightnessConsole %newlvl%,,Hide
      break
   }
}
RunWait %comspec% /c DisplayBrightnessConsole>current.txt,,Hide
FileReadLine, currentlvl, current.txt, 1
return
#MaxThreadsBuffer Off

*F7::
GetKeyState, state, Alt
if (state = "D")
{
   SendInput, {F7}
   Exit
}
Run %ComSpec% /c "nircmd.exe monitor off",,Hide
sleep 2000
Process, close, nircmd.exe
return

LabelKill:
   RunWait %comspec% /c DisplayBrightnessConsole>current.txt,,Hide
   FileReadLine, currentlvl, current.txt, 1
   Process, close, nircmd.exe
return


you can grab the needed files from my earlier post or just run my precompiled version (brightness_v2.exe) and they will auto extract.

brightness_v2.exe

Enjoy!
-Aaron


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, chaosad, oldbrother and 19 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group