Help with Input.check while holding multiple keys


(Jacob) #1

I’m trying to do something for a situation where the user is holding multiple keys. The game records the order in which they were pressed into an Array and on Input.released that key will be spliced from the Array. This is so as the player releases keys, of the remaining held, only the last one in the Array will be processed. The problem I’m running into is that Input.check seems to only process, at the most, 3 keys held, but usually 2. I made a basic Entity just to test:

public class Test3 extends Entity 
	{
		
		public function Test3(x:Number=0, y:Number=0, graphic:Graphic=null, mask:Mask=null) 
		{
			super(x, y, graphic, mask);
			
		}
		
		override public function update():void 
		{
			super.update();
			
			
			updateInput();
		}
		
		private function updateInput():void
		{
			if (Input.check(Key.UP)) trace("UP");
			if (Input.check(Key.RIGHT)) trace("RIGHT");
			if (Input.check(Key.DOWN)) trace("DOWN");
			if (Input.check(Key.LEFT)) trace("LEFT");
		}
		
	}

Lets say I press and hold, in order, Key.LEFT, Key.UP, Key.RIGHT. Output traces LEFT UP LEFT UP LEFT UP LEFT UP LEFT UP LEFT UP LEFT UP. Does not trace RIGHT.


(Hussein Tammam) #2

Unfortunately this isn’t a problem with flashpunk itself but rather a hardware limitation due to the way keyboards are designed. You’re experiencing what’s called “keyboard ghosting”. Basically its when a keyboard key doesnt work when you press down a certain combination of keys at the same time. Here’s an article by the microsoft applied sciences group if you’d like to read more about it.

Considering that most people don’t have anti-ghosting keyboards you should probably rethink the way you solve the issue. Maybe if you elaborate on the problem a bit more I could help. Is this just for movement or a specific game mechanic?


(Jacob) #3

Hussein, thank you very much! This is very interesting. I was not expecting something like that.

I’ve been messing around with a twin stick shooter and wanted to implement something that would shoot in the direction based off the history of the held shoot keys. This is under my assumption it would be more user friendly.


(Zachary Lewis) #4

You’ll want a keyboard with n-key rollover.

Here’s a video explaining it.


(Nicole Brauer) #5

Not being able to duck-jump diagonally forward and swapping weapons at the same time in Half-Life 2 is the bane of my existence.


(Zachary Lewis) #6

Gotta’ upgrade your keyboard. Go for a tenkeyless mechanical one!


(Martí Angelats i Ribera) #7

They are expensive though. D: