Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Surface Pro 3 script help (brightness)


  • Please log in to reply
2 replies to this topic
blackice5674
  • New members
  • 2 posts
  • Last active: Sep 17 2015 05:01 PM
  • Joined: 11 Sep 2015

So I was reading through some previous threads and found a script that said it would make the windows + f1/f2 keys on the surface pro type cover change the actual surface screen brightness. However this script didn't end up working. Below is a copy of this specific part of the script. Does anyone know anything that would work? Or what the command for screen brightness for a surface pro 3 would be?

 

;;;;;;;;;;;;;;;; brightness shortcuts for surface type cover ;;;;;;;;;;;;;;;;;;
 
toggle := false
 
SetWorkingDir %A_ScriptDir%
SendMode, Input
 
;;SC108::  ; SAMSUNG brightness up FN key
;;^+#!Up::
#F2::
MoveBrightness(10)
return
 
;;SC109::  ; SAMSUNG brightness down FN key
;;^+#!Down::
#F1::
MoveBrightness(-10)
return
 
#Escape::SendMessage 0x112, 0xF170, 2, , Program Manager
 
;############################################################################
; Functions
;############################################################################
 
MoveBrightness(IndexMove)
{
 
VarSetCapacity(SupportedBrightness, 256, 0)
VarSetCapacity(SupportedBrightnessSize, 4, 0)
VarSetCapacity(BrightnessSize, 4, 0)
VarSetCapacity(Brightness, 3, 0)
 
hLCD := DllCall("CreateFile"
, Str, "\\.\LCD"
, UInt, 0x80000000 | 0x40000000 ;Read | Write
, UInt, 0x1 | 0x2  ; File Read | File Write
, UInt, 0
, UInt, 0x3  ; open any existing file
, UInt, 0
 , UInt, 0)
 
if hLCD != -1
{
 
DevVideo := 0x00000023, BuffMethod := 0, Fileacces := 0
 NumPut(0x03, Brightness, 0, "UChar")   ; 0x01 = Set AC, 0x02 = Set DC, 0x03 = Set both
 NumPut(0x00, Brightness, 1, "UChar")      ; The AC brightness level
 NumPut(0x00, Brightness, 2, "UChar")      ; The DC brightness level
DllCall("DeviceIoControl"
 , UInt, hLCD
 , UInt, (DevVideo<<16 | 0x126<<2 | BuffMethod<<14 | Fileacces) ; IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS
 , UInt, 0
 , UInt, 0
 , UInt, &Brightness
 , UInt, 3
 , UInt, &BrightnessSize
 , UInt, 0)
 
DllCall("DeviceIoControl"
 , UInt, hLCD
 , UInt, (DevVideo<<16 | 0x125<<2 | BuffMethod<<14 | Fileacces) ; IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS
 , UInt, 0
 , UInt, 0
 , UInt, &SupportedBrightness
 , UInt, 256
 , UInt, &SupportedBrightnessSize
 , UInt, 0)
 
ACBrightness := NumGet(Brightness, 1, "UChar")
ACIndex := 0
DCBrightness := NumGet(Brightness, 2, "UChar")
DCIndex := 0
BufferSize := NumGet(SupportedBrightnessSize, 0, "UInt")
MaxIndex := BufferSize-1
 
Loop, %BufferSize%
{
ThisIndex := A_Index-1
ThisBrightness := NumGet(SupportedBrightness, ThisIndex, "UChar")
if ACBrightness = %ThisBrightness%
ACIndex := ThisIndex
if DCBrightness = %ThisBrightness%
DCIndex := ThisIndex
}
 
if DCIndex >= %ACIndex%
 BrightnessIndex := DCIndex
else
 BrightnessIndex := ACIndex
 
BrightnessIndex += IndexMove
 
if BrightnessIndex > %MaxIndex%
  BrightnessIndex := MaxIndex
  
if BrightnessIndex < 0
  BrightnessIndex := 0
 
NewBrightness := NumGet(SupportedBrightness, BrightnessIndex, "UChar")
 
NumPut(0x03, Brightness, 0, "UChar")   ; 0x01 = Set AC, 0x02 = Set DC, 0x03 = Set both
        NumPut(NewBrightness, Brightness, 1, "UChar")      ; The AC brightness level
        NumPut(NewBrightness, Brightness, 2, "UChar")      ; The DC brightness level
 
DllCall("DeviceIoControl"
, UInt, hLCD
, UInt, (DevVideo<<16 | 0x127<<2 | BuffMethod<<14 | Fileacces) ; IOCTL_VIDEO_SET_DISPLAY_BRIGHTNESS
, UInt, &Brightness
, UInt, 3
, UInt, 0
, UInt, 0
, UInt, 0
, Uint, 0)
 
DllCall("CloseHandle", UInt, hLCD)
 
}
 
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


jerbo
  • Members
  • 8 posts
  • Last active: Sep 27 2015 01:37 AM
  • Joined: 08 Jul 2012

Well, the standard keyboard commands for the Surface Pro 3 are:

 

Fn + Backspace  :  Decreases Brightness

Fn + Del              :  Increases Brightness

 

So not sure why you would want a script to do this.



Jack Dunning
  • Members
  • 217 posts
  • Last active: Nov 11 2015 08:40 PM
  • Joined: 08 Apr 2013

Here is a short script which creates a screen dimmer pop-up. It has the calls for controlling screen brightness. Don't know how well it will work for the Surface Pro 3.

Menu, Tray, Add, Reset, Reload
Menu, Tray, Add, Show Dimmer, ShowWindow
Menu, Tray, Add, Reset, Reload
Menu, Tray, Icon, Shell32.dll, 44
Menu, Tray, Default, Show Dimmer
Menu, Tray, Click, 1

Gui +AlwaysOnTop
Gui, Add, Text, vDim x0 y0, Dimmer
Gui, Add, Text, vBright x0 y0, Brighter
Options := "Range60-180 NoTicks Buddy1Dim Buddy2Bright vMySlider gDimmer"
Gui, Add, Slider, W200 x50 y5 AltSubmit Tooltip Reverse %options% , 128
Gui, Add, StatusBar, gReset, Default Brightness 128 `t`t(Click Status Bar to Reset)
Gui, Show, W300, Screen Brightness
SB_SetIcon("Shell32.dll", 44)
DisplaySetBrightness( 128 )
Return

Dimmer:
  Gui, Submit, NoHide
  DisplaySetBrightness( MySlider )
  SB_SetText("Brightness level is " . MySlider . "`t`t(Click Status Bar to Reset)")
Return

DisplaySetBrightness( Br=128 ) {
 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 )
 Return DllCall( "SetDeviceGammaRamp", UInt,hDC := DllCall( "GetDC", UInt,0 ), UInt,&GR )
     , DllCall( "ReleaseDC", UInt,0, UInt,hDC )
}

ShowWindow:
 DetectHiddenWindows, on
 WinRestore, Screen Brightness
 WinActivate, Screen Brightness
Return

Reload:
 Reload
Return

Reset:
  DisplaySetBrightness( 128 )
  GuiControl, , MySlider, 128
  SB_SetText("Default Brightness 128`t`t(Click Status Bar to Reset)")
Return

I currently do a regular blog for AutoHotkey beginners and have posted a number of AutoHotkey help pages at ComputorEdge.com. As I learn, I pass it on.

 

AutoHotkey scripts and apps for beginners and more ideas.