Toggling aim in games

Ask gaming related questions (AHK v1.1 and older)
Aleque
Posts: 14
Joined: 24 Apr 2021, 16:55

Toggling aim in games

15 May 2021, 01:46

Hi

I would like to use two different keys (Numpad2 and RButton) to have the same function in games that don't have aim-toggle option. So far, one of he buttons works using this code:

Code: Select all

RButton::
KeyDown := !KeyDown
If KeyDown
	SendInput {RButton down}
Else
	SendInput {RButton up}
Return
But if I add another one below..

Code: Select all

Numpad2::
KeyDown := !KeyDown
If KeyDown
	SendInput {Numpad2 down}
Else
	SendInput {Numpad2 up}
Return
..then anoher one stops functioning.

How do I do it so that if Numpad2 activates the toggle, I can also disable it using RButton and vice versa?


For instance, if I use Numpad2 to aim-toggle, then I could disable it again using RButton. And if I use RButton to aim-toggle, then I could disable it again using Numpad2.

Example (4 scenarios):

1). Button A activates the Button A toggle, Button A deactivates the Button A toggle.
2). Button B activates the Button B toggle, Button B deactivates the Button B toggle.
3). Button A activates the Button A toggle, Button B deactivates the Button A toggle.
4). Button B activates the Button B toggle, Button A deactivates the Button A toggle.

So that Numpad2 can be a substitute for RButton and vice versa.

How do I achieve this?


Thanks
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Toggling aim in games

15 May 2021, 07:40

Code: Select all

OnExit("done"), other := {RButton: "Numpad2", Numpad2: "RButton"}, keyDown := {}
RButton::
$Numpad2::
If !keyDown[hk := StrReplace(A_ThisHotkey, "$")] := !keyDown[hk] {
 Send % "{" hk " up}{" other[hk] " up}"
 keyDown[other[hk]] := False
} Else Send {%hk% down}
KeyWait, %hk%
Return

done(ExitReason, ExitCode) {
 Send {RButton up}{Numpad2 up}
}
Aleque
Posts: 14
Joined: 24 Apr 2021, 16:55

Re: Toggling aim in games

15 May 2021, 10:51

Hi

I get this error:

https://imgur.com/a/wb8QlBB
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Toggling aim in games

15 May 2021, 11:14

It looks like you are using a different script than the one that I posted. Would try this one first, with nothing else in the script. Don't forget to include the "done" function at the end. Test in Notepad. If you click "Select All", it will enable you to select the entire script. You can then copy it, and paste it into a blank text file.
Aleque
Posts: 14
Joined: 24 Apr 2021, 16:55

Re: Toggling aim in games

15 May 2021, 11:25

You, sir, are awesome! Thanks for the help, it works perfectly :)
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Toggling aim in games

15 May 2021, 11:51

Great!

The following might also work.

Code: Select all

OnExit("done"), other := {RButton: "Numpad2", Numpad2: "RButton"}, keyDown := {}
RButton::
$Numpad2::
If keyDown[hk := StrReplace(A_ThisHotkey, "$")] := !keyDown[hk]
 Send {%hk% down}
Else done(), keyDown[other[hk]] := False
KeyWait, %hk%
Return

done(ExitReason := "", ExitCode := "") {
 Send {RButton up}{Numpad2 up}
}

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 43 guests