Multiple Keys, but cancel each other

Ask gaming related questions (AHK v1.1 and older)
Cremona
Posts: 1
Joined: 09 Apr 2024, 15:08

Multiple Keys, but cancel each other

Post by Cremona » 09 Apr 2024, 15:14

Hello, I wanted to make a script where when I press F2, it presses Insert for an infinite amount at 50ms interval, and for F3 it presses End for an infinite amount at 50ms interval, but when i press the F2 it also cancels the F3 function and when i press the F3 it also cancels the F2 function, can someone help with the script pls ? thanks before

Code: Select all

F2::
SetTimer, PressTheKey, % (toggle:=!toggle) ? : "Off"
Return

PressTheKey:
Send, {Insert}
Sleep 50
Send, {Insert}

Return


F3::
SetTimer, PressTheKey2, % (toggle:=!toggle) ? : "Off"
Return

PressTheKey2:
Send, {End}
Sleep 50
Send, {End}

Return
Last edited by gregster on 09 Apr 2024, 17:14, edited 2 times in total.
Reason: joedf added code tags. I moved the topic from "Scripts and Functions (v2)" to v1 help since is not v2 code, and also not a working script but a help request.

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

Re: Multiple Keys, but cancel each other

Post by Rohwedder » 10 Apr 2024, 02:02

Hallo,
try:

Code: Select all

F2::SetTimer, PressTheKey, % (F2:=!F2) ? 50 : "Off"
PressTheKey:
Send, {Insert}
Return
F3::SetTimer, PressTheKey2, % (F3:=!F3) ? 50 : "Off"
PressTheKey2:
Send, {End}
Return
or:

Code: Select all

F2::SetTimer, F2 Up, % (F2:=!F2) ? 50 : "Off"
F2 Up::Send,% F2 ? "{Insert}" : ""
F3::SetTimer, F3 Up, % (F3:=!F3) ? 50 : "Off"
F3 Up::Send,% F3 ? "{End}" : ""
or:

Code: Select all

F2::SetTimer, F2 Up, % (F2:=!F2) ? 50 : "Off"
F2 Up::Send,% ["{Insert}"][F2]
F3::SetTimer, F3 Up, % (F3:=!F3) ? 50 : "Off"
F3 Up::Send,% ["{End}"][F3]
Different toggles require different toggle variables.

Post Reply

Return to “Gaming Help (v1)”