Bizarre KeyDown Behavior/Bug

I’m really not sure how to pinpoint the problem here. In my game, I have the player character moving with the WASD keys and performing actions with J, K, U, I, N, and M. For some reason, whenever the player is holding down J to shoot and attempts to move up and left by holding down W and A, this will not work. Whichever direction key was pressed first will go into effect, but the second won’t turn it into diagonal movement. For example if the player is shooting by holding down J, then holds A to move left, this will work fine. If the player then presses W to go up and to the left while shooting, the player will continue traveling to the left and won’t go up at all. The strange part of the problem is that the player can go up and left while not performing an action, or while performing the actions mapped to other keys that aren’t J. Even stranger, if I use my key mapping screen to change the basic shooting action to another key, this will then work. If I map a different action to J, this will then fail to work as in the original case despite working with a different key set.

I’ve done everything I can to verify that this isn’t an issue with my code. I’ve changed up which keys I use for both directional movement and actions, and I’ve used the debugger to ensure that all of the data other than the per-frame keydown information is as it should be. No matter what I do, it seems like for whatever reason Phaser isn’t recognizing an A/W keypress if J and W/A are held down. Every other combination I’ve tried seems to work just fine. I’m really at a loss for what’s going on here. For now the solution is to simply change my default control scheme and everything works fine, but I’d really love to figure out what is going on here. I’ve included relevant code snippets and am using a minimized version of Phaser downloaded today.

//Control.js
Movement()
{
	
	return {x: 0, y: 0};
	
}

//Input.js, inherits Control.js
Movement()
{
	var velocity = super.Movement();
	if(this.Left())
	{
		velocity.x -= 1;
	}

	if(this.Right())
	{
		velocity.x += 1;
	}


	if(this.Up())
	{
		velocity.y -= 1;
	}

	        if(this.Down())
	{
		velocity.y += 1;
	}
	
	return velocity;
}

Left()
{
	return this.keys.left.isDown;
}

Right()
{
	return this.keys.right.isDown;
}

Up()
{
	return this.keys.up.isDown;
}

Down()
{
	return this.keys.down.isDown;
}

//Player.js
MovementUpdate()
{
	
	this.setVelocityX(0);
	this.setVelocityY(0);
	
	var velocity = this.control.Movement();
	
	this.setVelocityX(velocity.x * this.horizontalVelocity);
	this.setVelocityY(velocity.y * this.verticalVelocity);
	
}

What happens when you press these combinations in notepad or another editor?
It could be your keyboard just isn’t wired for it.

Testing in an editor didn’t really work, as it just used the last key pressed which I assume would be the expected behavior. However, you made me think to try it in another game and the same thing applies, so it does appear to be my keyboard. Still very strange, but good to know it’s not a problem with Phaser.

Maybe try with a different browser or with your browser “safe mode”. I had keydown bugs on Firefox for some reasons and it would disappear when trying with Chrome.

Hi,
Just to point you to the real problem, it’s called keyboard ghosting.
A test page here:
https://drakeirving.github.io/MultiKeyDisplay/
And an explanation here
Keyboard Ghosting and the SideWinder X4 | Applied Sciences | Microsoft.

1 Like

Yes, after the first comment I had looked into the hardware side of things more and read up on this. I had recently switched to an older keyboard because my usual one stopped working, which is what caused the issue to crop up.