Code: Select all
$#vk4e::
If (A_ThisHotKey = A_PriorHotkey and A_TimeSincePriorHotkey < 300) {
; action 1
}
else {
; action 2
}
return
Can you please help?
Code: Select all
$#vk4e::
If (A_ThisHotKey = A_PriorHotkey and A_TimeSincePriorHotkey < 300) {
; action 1
}
else {
; action 2
}
return
Code: Select all
<#a:: ; <# means LWin
count++ ; for each press, increment a counter
If (count=1)
SetTimer action, -50
return
action:
KeyWait, LWin, L
If (count=1)
MsgBox, action 1
If (count=2)
MsgBox, action 2
; ...
count:=0 ; reset counter
return
Code: Select all
#vk4e::
keywait, vk4e ; up first key
keywait, vk4e, d t0.2 ; 2nd key?
if errorlevel
send 1
else
send 2
return
But... but... GEV's solution worked perfectly, actually. The logic is that script waits while I release modifier key (Win key in my case), and while waiting, counts the other key presses. This way I can wait for however long between key presses and it still runs either action 1 OR action 2, as long as I don't release the win key between presses, which I have no reason to. This is perfect!evilC wrote:AHK is not a time machine
If you wish to implement logic like this for a given key, you need to define a timeout period, and take no action until that timeout expires.
If the user presses a second time within the timeout, send action #2, else send action #1
There is no other way to solve this if you only wish to ever send 1 action.
So yeah, Xeno's post appears about on the money.
Code: Select all
<#a:: ; <# means LWin
count++ ; for each press, increment a counter
SetTimer action, -0 ; SetTimer is only used here to cause the code to be jumped to in a psuedo-thread.
return
action:
KeyWait, LWin, L
If (count=1)
MsgBox, action 1
If (count=2)
MsgBox, action 2
; ...
count:=0 ; reset counter
return
It seems to work fine for me. Also keep in mind if you have other parts of your script that need 2+ threads per hotkey you can have several directives for that.for some reason it doesn't work if I use #MaxThreadsPerHotkey limit (regardless of which limit I set).
Code: Select all
#MaxThreadsPerHotkey 2
f1::
sleep 3000
send a
return
#MaxThreadsPerHotkey 1
#vk4e::
keywait, vk4e ; up first key
keywait, vk4e, d t0.2 ; 2nd key?
if errorlevel
send 1
else
send 2
return
Users browsing this forum: Bing [Bot], Google [Bot], oktavimark and 372 guests