Changing brightness and dimming screen with one hotkey

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Net_Wars
Posts: 51
Joined: 10 Oct 2018, 11:11

Changing brightness and dimming screen with one hotkey

10 Nov 2018, 07:49

Hi,
Is it possible to change brightness and dimm screen using one hotkey?
For me it should work like this:
if the screen brightness := 0 then (while pressing LWin & A) it will dimm the screen
also if the dimm level :=0 then (while pressing LWin & D) it will change screen brightness

I've got BrightnessSetter by qwerty12 and Screen dimmer program by dangerdogL2121 (changed a little bit)

BrightnessSetter is using variable %currBrightness% for storing current brightness level

This is where I want it to be placed
Spoiler
And this is dangerdogL2121 dimmer script (changed by me)
;next spoilers contains rest of script
Spoiler

Code: Select all

LWin & q::
editspeed+=10
Gosub,dim
GuiControl,, MyProgress, +-10
transparent=0
Gosub,fade
return
LWin & e::
editspeed-=10
Gosub,dim
GuiControl,, MyProgress, +10
transparent=0
Gosub,fade
return
Spoiler
If its possible please help me.
Its not very important (as You can see I'm using LWin & Q and LWin & E hotkeys instead)

Sorry if my English is little bad.
Thanks in advance for your help
Hi,
I was trying make this on my own but I'm good only in basics not good even in basics. :facepalm:

Sorry for my bad English. If something is unclear I will try better next time. :headwall:
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: Changing brightness and dimming screen with one hotkey

11 Nov 2018, 11:46

Press and hold hotkey to increase brightness, & tap repeatedly to decrease it...

Code: Select all

i:=0

LWin::
KeyWait, %A_ThisHotkey%, T0.2
If ErrorLevel		;if being held & while it continues to be held
	ToolTip % i++
else				;if being pressed
	ToolTip % i--
Return

Code: Select all

LWin::
KeyWait, %A_ThisHotkey%, T0.2
If ErrorLevel		;if being held & while it continues to be held
	BrightnessSetter.SetBrightness(10)
else				;if being tapped
	BrightnessSetter.SetBrightness(-10)
Return
live ? long & prosper : regards
Net_Wars
Posts: 51
Joined: 10 Oct 2018, 11:11

Re: Changing brightness and dimming screen with one hotkey

11 Nov 2018, 15:31

That's not what I'm looking for.
My idea was to use one hotkey to do two things.
I've got another question related to my problem
Is it possible to suspend only two hotkeys from script containing many of them or make something like profiles? Maybe I can use ScrollLock to change action of this hotkeys?
Hi,
I was trying make this on my own but I'm good only in basics not good even in basics. :facepalm:

Sorry for my bad English. If something is unclear I will try better next time. :headwall:
CyL0N
Posts: 211
Joined: 27 Sep 2018, 09:58

Re: Changing brightness and dimming screen with one hotkey

12 Nov 2018, 02:54

Ehmm, it is a SINGLE hotkey that does two things,you just either TAP or HOLD,unless there's another way to use a single hotkey for different things,which in case there is, i too would like to know...

As For Selectively 'Suspending' Hotkeys,it's easy enough...

Code: Select all

weAreAllowed := True

#If weAreAllowed
x::
y::
MsgBox We Are Allowed
Return
#If


LWin::
MsgBox A Third Hotkey to disable,the other two...
weAreAllowed := False
Return
live ? long & prosper : regards
oif2003
Posts: 214
Joined: 17 Oct 2018, 11:43
Contact:

Re: Changing brightness and dimming screen with one hotkey

15 Nov 2018, 04:09

You can assign the number of keypresses within an allotted time to trigger different actions. For example:
1 press = +25% brightness, and stacks up to 4 times (100%) as long as the keypresses are within 400 ms.
Here's an example taken from AutoHotkey v2's documentation on SetTimer:

Code: Select all

#SingleInstance Force
; Example #3: Detection of single, double, and triple-presses of a hotkey. This
; allows a hotkey to perform a different operation depending on how many times
; you press it:
#c::
KeyWinC()  ; This is a function hotkey.
{
    static winc_presses := 0
    if winc_presses > 0 ; SetTimer already started, so we log the keypress instead.
    {
        winc_presses += 1
        return
    }
    ; Otherwise, this is the first press of a new series. Set count to 1 and start
    ; the timer:
    winc_presses := 1
    SetTimer "After400", -400 ; Wait for more presses within a 400 millisecond window.

    After400()  ; This is a nested function.
    {
        if winc_presses = 1 ; The key was pressed once.
        {
            MsgBox "One click detected."  
        }
        else if winc_presses = 2 ; The key was pressed twice.
        {
            MsgBox "Two clicks detected." 
        }
        else if winc_presses > 2
        {
            MsgBox "Three or more clicks detected."
        }
        ; Regardless of which action above was triggered, reset the count to
        ; prepare for the next series of presses:
        winc_presses := 0
    }
}
oif2003
Posts: 214
Joined: 17 Oct 2018, 11:43
Contact:

Re: Changing brightness and dimming screen with one hotkey

15 Nov 2018, 04:43

Here's a version that refreshes the timer. It will continue to take in keypresses as long as the current keypress is within a given time period of the previous one. This will allow you to stack up to any amount of keypresses you want. (Note: for AHK v2)

Code: Select all

#SingleInstance Force
timeOutInterval := 300	;set the maximum allowed interval between keys in milliseconds

`:: 
keypress() {
	global timeOutInterval
	static pressCount := 0
	
	pressCount++
	currCount := pressCount	;the number of keypresses when we start the timer
	SetTimer(()=>expired(), -timeOutInterval)
	
	expired() {
		; if timer expires without seeing more keypresses
		if currCount == pressCount {
			;Do stuff based on number of keypresses
			ToolTip(pressCount " presses detected.")
			SetTimer(()=>ToolTip(), -1000)
			
			pressCount := 0
		}	
	}
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mikeyww, Raghava Doregowda and 335 guests