Code: Select all
1::
{
;this is my first code
return
2::
{
;This is my second code
}
return
f::
{
sleep, 4000
sendinput, {Lshift down}
sleep, 10
sendinput, {Lshift up}
sleep, 200
sendinput, {d down}
sleep, 100
sendinput, {d up}
return
}
Code: Select all
1::
{
;this is my first code
return
2::
{
;This is my second code
}
return
f::
{
sleep, 4000
sendinput, {Lshift down}
sleep, 10
sendinput, {Lshift up}
sleep, 200
sendinput, {d down}
sleep, 100
sendinput, {d up}
return
}
Code: Select all
f Up::
{
KeyWait, f, D T4
if ErrorLevel = 0
{
return
}
sendinput, {Lshift down}
sleep, 10
sendinput, {Lshift up}
sleep, 200
sendinput, {d down}
sleep, 100
sendinput, {d up}
return
}
Code: Select all
#Requires AutoHotkey v1.1.33
f::
SetTimer Go, -4000
SoundBeep 1500
Return
Go:
Send abc
Return
Code: Select all
#Requires AutoHotkey v2.0
f:: {
SetTimer go, -4000
SoundBeep 1500
}
go() {
Send 'abc'
}
Thanks, this works exactly like I want, but looking at the documentation for the "KeyWait" function, it only words for a single key press. Suppose I want to modify the script so that while it is waiting for 4000 ms, it checks if "Lshift" is press and if "Lshift" is press, then it exits "f UP::"DustinLuck wrote: ↑10 Jan 2023, 23:13Try the following code. After the F key is released, it will wait for four seconds to see if the F key is pressed again. If it is, the first iteration will be canceled.
Code: Select all
f Up:: { KeyWait, f, D T4 if ErrorLevel = 0 { return } sendinput, {Lshift down} sleep, 10 sendinput, {Lshift up} sleep, 200 sendinput, {d down} sleep, 100 sendinput, {d up} return }
Code: Select all
~f Up::
{
start_time := A_TickCount
time_to_run := 4000
end_time := start_time + time_to_run
while (A_tickcount <= end_time)
{
if (GetKeyState("f"))
return
else
{
if (GetKeyState("LShift"))
Exit
}
}
sendinput, {Lshift down}
sleep, 10
sendinput, {Lshift up}
sleep, 200
sendinput, {d down}
sleep, 100
sendinput, {d up}
return
}
Return
Code: Select all
CancelF := false
~f Up::
{
CancelF := false
KeyWait, f, D T4
if (ErrorLevel = 0 OR CancelF)
{
return
}
sendinput, {Lshift down}
sleep, 10
sendinput, {Lshift up}
sleep, 200
sendinput, {d down}
sleep, 100
sendinput, {d up}
return
}
~Lshift::
{
CancelF := true
}
Users browsing this forum: No registered users and 231 guests