Disable/Block a Key with another Key while its pressed and held down.

Ask gaming related questions (AHK v1.1 and older)
Bubyoz
Posts: 8
Joined: 18 Feb 2017, 11:02

Disable/Block a Key with another Key while its pressed and held down.

22 May 2017, 14:03

So in this game im moving my charachter with the WASD keys, but if i hold down the A and D key at the same time,
the game register that as a forward movement (W key) so the charachter starts to move forward instead of the strafe actions.

So i need a code which is prevents the A and D key simultaneous pressing.

I tried a lot of Send / Down, Up codes but i just cant figure it out any ideas?

THX anyway :think:
neomulemi6
Posts: 216
Joined: 30 Jun 2016, 06:01

Re: Disable/Block a Key with another Key while its pressed and held down.

22 May 2017, 22:34

So you want A and D to override W, if W is already pressed? If so, this should work (untested).

Code: Select all

$a::
If (CheckKey("w"))
{
	Send {w up}
	While (GetKeyState("a", "p"))
	{
		Send {a down}
	}
	Send {w down}
} Else {
	Send {a down}
}
Return

$d::
If (CheckKey("w"))
{
	Send {w up}
	While (GetKeyState("d", "p"))
	{
		Send {d down}
	}
	Send {w down}
} Else {
	Send {d down}
}
Return

CheckKey(key)
{
	If (GetKeyState(key, "p"))
		Return 1
}
Bubyoz
Posts: 8
Joined: 18 Feb 2017, 11:02

Re: Disable/Block a Key with another Key while its pressed and held down.

22 May 2017, 22:42

Hey! Thx for the fast reply!

BUT

I want A and D override each other (Im not using the W key), because if i hit both A and D at the same time my character moves forward, not like this \ /
and i want to avoid the forward movements.

I want insantly changed fast Left \ and Right / strafing only.

So i need a code only for the A and D! :)
Last edited by Bubyoz on 23 May 2017, 01:27, edited 1 time in total.
neomulemi6
Posts: 216
Joined: 30 Jun 2016, 06:01

Re: Disable/Block a Key with another Key while its pressed and held down.

22 May 2017, 22:52

That's a little easier. Does this work?

Code: Select all

~a::
If (GetKeyState("d", "p")
{
	Send {d up}
}
Return

~d::
If (GetKeyState("a", "p")
{
	Send {a up}
}
Return
Bubyoz
Posts: 8
Joined: 18 Feb 2017, 11:02

Re: Disable/Block a Key with another Key while its pressed and held down.

22 May 2017, 23:07

We are getting closer, cause its working basicly, but not continuously. It Stops after 1 direction change.

It does change directions from left to right or right to left perfectly while holding down both keys without moving forward.

BUT i cant change directions again, without letting the keys go. :?

for example: i hold down the A key for any time (charachter is strafing left), while im holding down the A key i hit the D key too
so it starts to strafe right but when i let the D key go it starts to move left again (Im still holding the A key).

SO basicly i want movement all the time if i hold down any of the 2 keys.
Attachments
Untitled-1.gif
Untitled-1.gif (22.08 KiB) Viewed 3870 times
neomulemi6
Posts: 216
Joined: 30 Jun 2016, 06:01

Re: Disable/Block a Key with another Key while its pressed and held down.

22 May 2017, 23:35

Sorry, I'm totally lost. I can't figure out how to make it work. :?
Bubyoz
Posts: 8
Joined: 18 Feb 2017, 11:02

Re: Disable/Block a Key with another Key while its pressed and held down.

22 May 2017, 23:40

my first question is do you fully understand my "Gibberish" ? :D

or

do you know someone? who can manage this somehow? its kinda important for competitive game training for me...
i even pay for it a few buck trough paypal if thats needed.

Dont leave me here im getting saaad :(
neomulemi6
Posts: 216
Joined: 30 Jun 2016, 06:01

Re: Disable/Block a Key with another Key while its pressed and held down.

22 May 2017, 23:45

Yeah, I know what you want, I just can't figure out how to make it work. I've tried several different methods. I hope somebody else can figure this out because I hate not being able to.

This is the closest I got. Might help somebody.

Code: Select all

~a::
If (GetKeyState("d", "p"))
{
	Send {d up}
	d = 1
}
Return

~d::
If (GetKeyState("a", "p"))
{
	Send {a up}
	a = 1
}
Return

a up::
If (d)
{
	Send {d down}
	d = 0
}
Return

d up::
If (a)
{
	Send {a down}
	a = 0
}
Return
Last edited by neomulemi6 on 22 May 2017, 23:52, edited 1 time in total.
Bubyoz
Posts: 8
Joined: 18 Feb 2017, 11:02

Re: Disable/Block a Key with another Key while its pressed and held down.

22 May 2017, 23:51

Okay man! thx for all the care! topic is open lets hope :D
and dont give up who knows maybe in the next couple of days ur gonna figure it out!
Bubyoz
Posts: 8
Joined: 18 Feb 2017, 11:02

Re: Disable/Block a Key with another Key while its pressed and held down.

23 May 2017, 01:39

hey i tested this code ingame. now its working! when i hold down any of the 2 keys the charachter change its direction.

BUT

after the few direction changes one of the keys are became toggled every time. like its getting hold down even when i dont press it. any idea?

good work btw!
donovv
Posts: 108
Joined: 15 Apr 2017, 21:06

Re: Disable/Block a Key with another Key while its pressed and held down.

23 May 2017, 01:40

not sure if this works but give it a go rofl

Code: Select all

$~a::
suspend on
main:
	while (getkeystate("a","P") = 1)
		{
		if (getkeystate("d","P") = 1)
			{
				while (getkeystate("d","P") = 1)
					{
						send {d down}
						sleep 10
						if (getkeystate("a","p") = 0)
							{
								keyheld := 1
								goto main
							}
					}
				send {d up}
			}
		send {a down}
		}
send {a up}
if keyheld = 1
	{
	while (getkeystate("d","P") = 1)
		{
			send {d down}
			sleep 10
		}
		keyheld := 0
	}			
suspend off
return 


$~d::
suspend on
main2:
	while (getkeystate("d","P") = 1)
		{
		if (getkeystate("a","P") = 1)
			{
				while (getkeystate("a","P") = 1)
					{
						send {a down}
						sleep 10
						if (getkeystate("d","p") = 0)
							{
								keyheld := 1
								goto main2
							}
					}
				send {a up}
			}
		send {d down}
		}
send {d up}
if keyheld = 1
	{
	while (getkeystate("a","P") = 1)
		{
			send {a down}
			sleep 10
		}
		keyheld := 0
	}			
suspend off
return 
Bubyoz
Posts: 8
Joined: 18 Feb 2017, 11:02

Re: Disable/Block a Key with another Key while its pressed and held down.

23 May 2017, 01:47

hey nice looking code there! :D
i tested and its not working!

@neomulemi6's idea is better cause A and D blocking each other, but in ure code they r not. at least not ingame or not like his! looks good tho :D
Bubyoz
Posts: 8
Joined: 18 Feb 2017, 11:02

Re: Disable/Block a Key with another Key while its pressed and held down.

29 May 2017, 03:51

working with this code?

Code: Select all

~a & d::
~d & a::
Send, {a up}
key := "d"
SetTimer, pressdown, 10
return

~d::key := "d"
~a::key := "a"
~a up::key := "d"
~d up::key := "a"

pressdown:
if GetKeyState(key, "p")
{
    SendInput, {%key% down}
    SetTimer, pressdown, 30
}
else {
    SetTimer, pressdown, Off
    SendInput, {%key% up}
}
return

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 101 guests