cancel action by pressing button

Ask gaming related questions (AHK v1.1 and older)
usernamewastaken
Posts: 5
Joined: 08 Nov 2021, 08:01

cancel action by pressing button

Post by usernamewastaken » 26 Jan 2022, 10:19

Hey guys, so I have this script here:

Code: Select all

~*Rbutton::
GetkeyState, Shift, Shift
if shift = D
 Send, {ShiftUp}
else if shift = U
 Send, {ShiftDown}
Return,
[Mod edit: [code][/code] tags added.]

The idea is when I click on the RMB (toggle to ADS in video game) I want SHIFT (hold breath in video game) to be activated at the same time (TOGGLE, not HOLD)
When I press RMB after, it cancels the action (SHIFT button) and I like it, but I also want to cancel action by pressing "R" button.
So is there any way to cancel the script (SHIFT) by pressing "R" button aswell?
Like: Press RMB once (script runs), Press RMB or R (script cancels)
By cancel, I mean cancel action, not suspend.

I had an idea to make something like this (but the first script would do fine, if you guys could just adjust it for me):

Code: Select all

*RButton::Shift
#If GetKeyState("RButton")
~r:: (that cancels the action if R is pressed)
*RButton Up::???? (idk what to write here)
#If
(keep in mind that I wanna the cancel action/script by either pressing "RMB" or "R")

But it doesn't work, I guess that I'm just too stupid... Help me out please :/
Thank you!

User avatar
boiler
Posts: 17044
Joined: 21 Dec 2014, 02:44

Re: cancel action by pressing button

Post by boiler » 26 Jan 2022, 10:56

If you just want the R button to cancel, just make a hotkey for it to release the Shift key:

Code: Select all

~*Rbutton::
GetkeyState, Shift, Shift
if shift = D
Send, {ShiftUp}
else if shift = U
Send, {ShiftDown}
Return

*r::Send, {ShiftUp} ; put ~ in front to retain R's native action

Since it's only needed when Shift is down, you could just use a + prefix instead of *. It mainly depends on if you want the R key to act as normal when Shift isn't down.

usernamewastaken
Posts: 5
Joined: 08 Nov 2021, 08:01

Re: cancel action by pressing button

Post by usernamewastaken » 26 Jan 2022, 11:57

boiler wrote:
26 Jan 2022, 10:56
If you just want the R button to cancel, just make a hotkey for it to release the Shift key:

Code: Select all

~*Rbutton::
GetkeyState, Shift, Shift
if shift = D
Send, {ShiftUp}
else if shift = U
Send, {ShiftDown}
Return

*r::Send, {ShiftUp} ; put ~ in front to retain R's native action

Since it's only needed when Shift is down, you could just use a + prefix instead of *. It mainly depends on if you want the R key to act as normal when Shift isn't down.
Hey, thank you for a quick reply.
Yes, it kinda works but at the same time it doesn't :^)
When I press R it cancels SHIFT but not the "RMB" which gets my character animation broken.
Is there any way to cancel both RMB+SHIFT by pressing R?
like, I was thinking.. maybe instead of using ~*Rbutton; I can use ~*Rbutton Up (
Sorry for being dumb and sorry for bad English lol

User avatar
boiler
Posts: 17044
Joined: 21 Dec 2014, 02:44

Re: cancel action by pressing button

Post by boiler » 26 Jan 2022, 12:17

I don't see that the RMB button continues to be pressed down after you press and release it, so I'm not sure what you're saying. But if you want R to also release the RMB, try this:

Code: Select all

~*Rbutton::
GetkeyState, Shift, Shift
if shift = D
Send, {ShiftUp}
else if shift = U
Send, {ShiftDown}
Return

*r::Send, {ShiftUp}{RButtonUp}

Post Reply

Return to “Gaming Help (v1)”