Bildschirmhelligkeit per Maustasten ändern

Post a reply


In an effort to prevent automatic submissions, we require that you complete the following challenge.
Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :| :mrgreen: :geek: :ugeek: :arrow: :angel: :clap: :crazy: :eh: :lolno: :problem: :shh: :shifty: :sick: :silent: :think: :thumbup: :thumbdown: :salute: :wave: :wtf: :yawn: :facepalm: :bravo: :dance: :beard: :morebeard: :xmas: :HeHe: :trollface: :cookie: :rainbow: :monkeysee: :monkeysay: :happybday: :headwall: :offtopic: :superhappy: :terms: :beer:
View more smilies

BBCode is ON
[img] is OFF
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Bildschirmhelligkeit per Maustasten ändern

Re: Bildschirmhelligkeit per Maustasten ändern

Post by deama » 26 Jul 2021, 22:12

jNizM wrote:
17 May 2015, 10:14
z.B. so

Code: Select all

#Persistent
OnExit, EOF

; ===============================================================================================================================

; Win + Numpad 4 (oder Numpad Pfeil Links)     ==>    Gamma -1 (runter) (Min:   0)
#Numpad4::     AdjustBrightness(-1)

; Win + Numpad 5 (oder Numpad 5)               ==>    Gamma zurück auf Ausgangswert (Normal 128)
#Numpad5::     DisplaySetBrightness(128)

; Win + Numpad 6 (oder Numpad Pfeil Rechts)    ==>    Gamma +1 (hoch)   (Max: 255)
#Numpad6::     AdjustBrightness(+1)

; ===============================================================================================================================

AdjustBrightness(V = 0)
{
    SB := (SB := DisplayGetBrightness() + V) > 255 ? 255 : SB < 0 ? 0 : SB
    DisplaySetBrightness(SB)
}

DisplaySetBrightness(SB := 128)
{
    loop % VarSetCapacity(GB, 1536) / 6
        NumPut((N := (SB + 128) * (A_Index - 1)) > 65535 ? 65535 : N, GB, 2 * (A_Index - 1), "UShort")
    DllCall("RtlMoveMemory", "Ptr", &GB +  512, "Ptr", &GB, "UPtr", 512, "Ptr")
    , DllCall("RtlMoveMemory", "Ptr", &GB + 1024, "Ptr", &GB, "UPtr", 512, "Ptr")
    return DllCall("gdi32.dll\SetDeviceGammaRamp", "Ptr", hDC := DllCall("user32.dll\GetDC", "Ptr", 0, "Ptr"), "Ptr", &GB), DllCall("user32.dll\ReleaseDC", "Ptr", 0, "Ptr", hDC)
}

DisplayGetBrightness(ByRef GB := "")
{
    VarSetCapacity(GB, 1536, 0)
    , DllCall("gdi32.dll\GetDeviceGammaRamp", "Ptr", hDC := DllCall("user32.dll\GetDC", "Ptr", 0, "Ptr"), "Ptr", &GB)
    return NumGet(GB, 2, "UShort") - 128, DllCall("user32.dll\ReleaseDC", "Ptr", 0, "Ptr", hDC)
}

; ===============================================================================================================================

EOF:
    DisplaySetBrightness(128)                 ; ==>    Gamma zurück auf Ausgangswert (Normal 128)
ExitApp
Hello,
Thanks for the script, works very well, however, is there a way to modify it so you can adjust the red, green, and blue gamma colours too?

Re: Bildschirmhelligkeit per Maustasten ändern

Post by lama0900 » 12 Feb 2018, 03:19

Danke, hervorragend :-)

Re: Bildschirmhelligkeit per Maustasten ändern

Post by gregster » 11 Feb 2018, 07:33

Habe Current-10 und Current+10 versucht, bekam einen Fehler
Vgl. https://autohotkey.com/docs/Variables.htm#Operators : Current-=10 bzw Current +=10 oder Current := Current - 10 etc.

Re: Bildschirmhelligkeit per Maustasten ändern

Post by lama0900 » 11 Feb 2018, 04:10

Hallo,

Ich kann zwar kleine AHK Scripte schreiben, aber bei dem von "just me" steig ich an der einen oder anderen Stelle nicht durch :bravo:

Was müsste geändert werden, damit die Helligkeit nicht um +1 oder -1 sondern +10 bzw. -10 geändert wird?
1er Schritte dauern mir zu lange :thumbup:

Habe Current-10 und Current+10 versucht, bekam einen Fehler

Vielen Dank im Voraus!

P.S.: Wollte keinen neuen Thread eröffnen, wenn es schon einen gibt.

Re: Bildschirmhelligkeit per Maustasten ändern

Post by just me » 17 May 2015, 10:41

Hallo und willkommen im Club!

DieFN-Tasten sind für AHK nicht auf allen Notebookmodellen problemlos erreichbar. Ich habe deshalb die Tastenkombinationen Shift+Ctrl++ und Shift+Ctrl+- vorbelegt, Du kannst es alllerdings auch mit anderen Kombinationen ausprobieren. Hier scheint es zu funktionieren, vielleicht bei Dir auch:

Code: Select all

#NoEnv
GetDisplayBrightness(Minimum, Current, Maximum) ; aktuelle Einstellungen abrufen
MsgBox, 0, Bildschirmhelligkeit, Minimum = %Minimum%`nAktuell = %Current%`nMaximum = %Maximum%
Return
; ======================================================================================================================
; Helligkeit erhöhen mit Shift+Ctrl++
+^+::
If (Current < Maximum) {
   Current++
   SetDisplayBrightness(Current)
   ToolTip, %Current%
   SetTimer, KillToolTip, -1000
}
Return
; ======================================================================================================================
; Helligkeit verringern mit Shift+Ctrl+-
+^-::
If (Current > Minimum) {
   Current--
   SetDisplayBrightness(Current)
   ToolTip, %Current%
   SetTimer, KillToolTip, -1000
}
Return
KillToolTip:
ToolTip
Return
; ======================================================================================================================
GetDisplayBrightness(ByRef Minimum, ByRef Current, ByRef Maximum) {
   HMON := DllCall("User32.dll\MonitorFromWindow", "Ptr", 0, "UInt", 0x02, "UPtr")
   DllCall("Dxva2.dll\GetNumberOfPhysicalMonitorsFromHMONITOR", "Ptr", HMON, "UIntP", PhysMons, "UInt")
   VarSetCapacity(PHYS_MONITORS, (A_PtrSize + 256) * PhysMons, 0) ; PHYSICAL_MONITORS
   DllCall("Dxva2.dll\GetPhysicalMonitorsFromHMONITOR", "Ptr", HMON, "UInt", PhysMons, "Ptr", &PHYS_MONITORS, "UInt")
   HPMON := NumGet(PHYS_MONITORS, 0, "UPtr")
   DllCall("Dxva2.dll\GetMonitorBrightness", "Ptr", HPMON, "UIntP", Minimum, "UIntP", Current, "UIntP", Maximum, "UInt")
   DllCall("Dxva2.dll\DestroyPhysicalMonitors", "UInt", PhysMons, "Ptr", &PHYS_MONITORS, "UInt")
}
; ======================================================================================================================
SetDisplayBrightness(Brightness) {
   Static Minimum := "", Current := "", Maximum := ""
   HMON := DllCall("User32.dll\MonitorFromWindow", "Ptr", 0, "UInt", 0x02, "UPtr")
   DllCall("Dxva2.dll\GetNumberOfPhysicalMonitorsFromHMONITOR", "Ptr", HMON, "UIntP", PhysMons, "UInt")
   VarSetCapacity(PHYS_MONITORS, (A_PtrSize + 256) * PhysMons, 0) ; PHYSICAL_MONITORS
   DllCall("Dxva2.dll\GetPhysicalMonitorsFromHMONITOR", "Ptr", HMON, "UInt", PhysMons, "Ptr", &PHYS_MONITORS, "UInt")
   HPMON := NumGet(PHYS_MONITORS, 0, "UPtr")
   DllCall("Dxva2.dll\GetMonitorBrightness", "Ptr", HPMON, "UIntP", Minimum, "UIntP", Current, "UIntP", Maximum, "UInt")
   If Brightness Is Not Integer
      Brightness := Current
   If (Brightness < Minimum)
      Brightness := Minimum
   If (Brightness > Maximum)
      Brightness := Maximum
   DllCall("Dxva2.dll\SetMonitorBrightness", "Ptr", HPMON, "UInt", Brightness, "UInt")
   DllCall("Dxva2.dll\DestroyPhysicalMonitors", "UInt", PhysMons, "Ptr", &PHYS_MONITORS, "UInt")
   Return Brightness
}
Edit: Es könnte gut sein, dass das erst ab Win Vista funktioniert.

Edit: Fehler im Dllcall DestroyPhysicalMonitors korrigiert. Danke, pneumatic

Re: Bildschirmhelligkeit per Maustasten ändern

Post by jNizM » 17 May 2015, 10:14

z.B. so

Code: Select all

#Persistent
OnExit, EOF

; ===============================================================================================================================

; Win + Numpad 4 (oder Numpad Pfeil Links)     ==>    Gamma -1 (runter) (Min:   0)
#Numpad4::     AdjustBrightness(-1)

; Win + Numpad 5 (oder Numpad 5)               ==>    Gamma zurück auf Ausgangswert (Normal 128)
#Numpad5::     DisplaySetBrightness(128)

; Win + Numpad 6 (oder Numpad Pfeil Rechts)    ==>    Gamma +1 (hoch)   (Max: 255)
#Numpad6::     AdjustBrightness(+1)

; ===============================================================================================================================

AdjustBrightness(V = 0)
{
    SB := (SB := DisplayGetBrightness() + V) > 255 ? 255 : SB < 0 ? 0 : SB
    DisplaySetBrightness(SB)
}

DisplaySetBrightness(SB := 128)
{
    loop % VarSetCapacity(GB, 1536) / 6
        NumPut((N := (SB + 128) * (A_Index - 1)) > 65535 ? 65535 : N, GB, 2 * (A_Index - 1), "UShort")
    DllCall("RtlMoveMemory", "Ptr", &GB +  512, "Ptr", &GB, "UPtr", 512, "Ptr")
    , DllCall("RtlMoveMemory", "Ptr", &GB + 1024, "Ptr", &GB, "UPtr", 512, "Ptr")
    return DllCall("gdi32.dll\SetDeviceGammaRamp", "Ptr", hDC := DllCall("user32.dll\GetDC", "Ptr", 0, "Ptr"), "Ptr", &GB), DllCall("user32.dll\ReleaseDC", "Ptr", 0, "Ptr", hDC)
}

DisplayGetBrightness(ByRef GB := "")
{
    VarSetCapacity(GB, 1536, 0)
    , DllCall("gdi32.dll\GetDeviceGammaRamp", "Ptr", hDC := DllCall("user32.dll\GetDC", "Ptr", 0, "Ptr"), "Ptr", &GB)
    return NumGet(GB, 2, "UShort") - 128, DllCall("user32.dll\ReleaseDC", "Ptr", 0, "Ptr", hDC)
}

; ===============================================================================================================================

EOF:
    DisplaySetBrightness(128)                 ; ==>    Gamma zurück auf Ausgangswert (Normal 128)
ExitApp

Bildschirmhelligkeit per Maustasten ändern

Post by kladamianus » 17 May 2015, 09:12

Ich brauche Hilfe!
Hallo, ihr Helfer bei AHK!
Ich habe mehrere Stunden in den Topics gesucht, aber mein Problem nicht gefunden.
Und habe erkannt, dass da richtige Profis am Werk sind. Ich ziehe meinen Hut.

Mein Problem:
Habe mir Kaffee auf die Laptop-Tastatur geschüttet.
Nun funktioniert die Tastenkombination "Fn" + "Coursertaste rechts" (Erhöht die Bildschirmhelligkeit) nicht mehr.
Die Tastenkombination "Fn" + "Coursertaste links" (Verringert die Bildschirmhelligkeit) funkioniert korrekt.
Nach dem Kaffeeunfall habe ich beiden Funktionen getestet und sitze nun IM DUNKELN!

Kann man die Steuerung der Bildschirmhelligkeit auf andere Tasten umprogrammieren?
Zum Beispiel:
"Fn" + "Linke Maustaste" (Erhöht die Bildschirmhelligkeit)
"Fn" + "Rechte Maustaste" (Verringert die Bildschirmhelligkeit)
oder irgend eine andere Kombination?

Nun bin ich nicht so ein Profi wie Ihr und hoffe, dass Ihr eine recht einfach zu verwirklichende Lösung für mich findet.
Der Laptop ist ein Windows XP-Rechner, SP3, Home Edition 5.1.2600, Build 2600 ohne Internetnuzung.

Vielen Dank vorab
Kladamianus

Top