tripple-timer or n-timer as activator

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
andreAga
Posts: 24
Joined: 01 Nov 2020, 22:02

tripple-timer or n-timer as activator

Post by andreAga » 09 Nov 2020, 03:14

Help me someone please with this.
When I hold the key less then or equal to 200 ms and release it, ahk fires on action number one but not action two, three, four,... N,...
if I hold this key greater than 200 ms but less then or equal to 500 ms and release it, it's fire on action two, but not the others. if I hold key n ms, it fire on an action N and so on.

I think that it can be realised with help of timers but I'm not shure.

So, I need special behavior depends on how long I press the button down. But the number of options is unlimited here. I hope it's understandable =).

Rohwedder
Posts: 7622
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: tripple-timer or n-timer as activator

Post by Rohwedder » 09 Nov 2020, 03:50

Hallo,
This measures the hold time of key Q and acts accordingly:

Code: Select all

q::
HoldTime := -A_TickCount
KeyWait, q
HoldTime += A_TickCount
If HoldTime < 100
	ToolTip,% HoldTime "ms is < 100ms" 
Else If HoldTime < 400
	ToolTip,% HoldTime "ms is 100 - 399ms"
Else
	ToolTip,% HoldTime "ms is >= 400ms"
Return

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: tripple-timer or n-timer as activator

Post by swagfag » 09 Nov 2020, 03:58

Code: Select all

q::
	KeyWait q

	if (A_TimeSinceThisHotkey < 200)
		action1()
	else if (A_TimeSinceThisHotkey < 500)
		action2()
	else
		action3()
Return

action1() {
}

action2() {
}

action3() {
}

Rohwedder
Posts: 7622
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: tripple-timer or n-timer as activator

Post by Rohwedder » 09 Nov 2020, 04:04

or something like that?:

Code: Select all

q:: ;press key Q once or twice, short or long
SetTimer, Timer, Off 
KeyWait, q
IF A_TimeSinceThisHotkey < 200
    Record .= "S" ;Short press
Else
    Record .= "L" ;Long press
IF StrLen(Record) > 1
    Goto, Timer
SetTimer, Timer, -500
Return
Timer:
Switch Record
{
Case "S":Send, 1
Case "L":Send, One
Case "SS":Send, 2
Case "SL":Send, Two 
Case "LS":Send, 3
Case "LL":Send, Three
}
Send, %A_Space%
;Tooltip for testing
ToolTip,% Record
Record =
Sleep, 1500
ToolTip
Return

andreAga
Posts: 24
Joined: 01 Nov 2020, 22:02

Re: tripple-timer or n-timer as activator

Post by andreAga » 09 Nov 2020, 04:38

yes, it's just what I need!
All of it works great and for me, a_tickcount is the best approach, for now. Thanks a lot

Post Reply

Return to “Ask for Help (v1)”