Be a Supporter!

Keyboard press not registering AS3

  • 320 Views
  • 7 Replies
New Topic Respond to this Topic
Barzona
Barzona
  • Member since: Jan. 4, 2009
  • Offline.
Forum Stats
Member
Level 13
Game Developer
Keyboard press not registering AS3 2013-08-10 03:54:08 Reply

Currently, when I play this game I'm working on, I noticed that when I'm pressing the spacebar to fire bullets, I cannot move the player in a Northwest direction by pressing the Up and Left key together. I can movie in all 7 other directions by pressing other keys together or by themselves, but I'm only not able to use Up and Left together while holding the Spacebar. If I release the spacebar I can move Northwest again.

Here's the demo so you can see what I mean.

Here's the Keyboard code as far as I think you need to see:

in my Player.as:

private function PressAKey(event:KeyboardEvent):void
{
	if(event.keyCode == 39)
	{
	 rightKey = true;
	}
	
	if(event.keyCode == 37)
	{
	 leftKey = true;
	}
	
	if(event.keyCode == 38)
	{
	 upKey = true;
	}
	
	if(event.keyCode == 40)
	{
	 downKey = true;
	}
}

and my spacebar code in my DocumentClass.as:

private function onSpaceDown(event:KeyboardEvent):void
		{
				if(event.keyCode == 32)
					{
	 					isFiring = true;
						isSideFiring = true;
					}
		}

		private function onSpaceUp(event:KeyboardEvent):void
		{
				if(event.keyCode == 32)
					{
	 					isFiring = false;
						isSideFiring = false;
					}
		}

This is a new issue ever since I decided to use the spacebar instead of the mouse to fire bullets. Maybe I could just introduce some kind of auto-fire to avoid the problem, I assume, entirely.

Has anyone heard of any issue like this before? If you need to see more code, just ask.

nitokov
nitokov
  • Member since: May. 8, 2012
  • Offline.
Forum Stats
Member
Level 05
Programmer
Response to Keyboard press not registering AS3 2013-08-10 07:35:19 Reply

issue could be with keyboard, only so many keys can be pressed at same time.
Alternatively try binding fire action on some other key and see if it resolve issue, or use wasd for movement


RangeError: Error #1125: The index 4 is out of range 4.

MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to Keyboard press not registering AS3 2013-08-10 07:39:02 Reply

Nothing you can do about that. Switch keys or implement auto fire.

Barzona
Barzona
  • Member since: Jan. 4, 2009
  • Offline.
Forum Stats
Member
Level 13
Game Developer
Response to Keyboard press not registering AS3 2013-08-10 11:59:42 Reply

At 8/10/13 07:35 AM, nitokov wrote: issue could be with keyboard, only so many keys can be pressed at same time.
Alternatively try binding fire action on some other key and see if it resolve issue, or use wasd for movement

It's not the number of key being pressed. I can press upwards of 4 at a time on this keyboard. I'm able to hold spacebar and still press "Down" and "Right". Those register. The only combination I can't seem to use is "Up" and "Left".

4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to Keyboard press not registering AS3 2013-08-10 12:24:19 Reply

At 8/10/13 11:59 AM, Barzona wrote:
At 8/10/13 07:35 AM, nitokov wrote: issue could be with keyboard, only so many keys can be pressed at same time.
Alternatively try binding fire action on some other key and see if it resolve issue, or use wasd for movement
It's not the number of key being pressed. I can press upwards of 4 at a time on this keyboard. I'm able to hold spacebar and still press "Down" and "Right". Those register. The only combination I can't seem to use is "Up" and "Left".

It's not just about the number of keys, but what those keys are. I remember someone mentioning how, due to the way keyboards are made, like the keys are in "groups", so you can't press that specific key combination.

egg82
egg82
  • Member since: Jun. 24, 2006
  • Offline.
Forum Stats
Supporter
Level 05
Game Developer
Response to Keyboard press not registering AS3 2013-08-11 20:16:31 Reply

At 8/10/13 12:24 PM, 4urentertainment wrote: It's not just about the number of keys, but what those keys are. I remember someone mentioning how, due to the way keyboards are made, like the keys are in "groups", so you can't press that specific key combination.

that's a sign of a bad keyboard, but yeah. A lot of people have bad keyboards.


Programming stuffs (tutorials and extras)
PM me (instead of MintPaw) if you're confuzzled.
thank Skaren for the sig :P

BBS Signature
Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Keyboard press not registering AS3 2013-08-11 20:47:00 Reply

I can do it on my Logitech G105 keyboard, so your code works fine.

You'll need to buy a better keyboard if you want it to work for you as well. Though as egg82 pointed out most users won't have a good enough keyboard for it to work, so I wouldn't recommend designing your game around it. One solution could be to let the user define the keys themselves, since it's possible that on their keyboard a different combination will work.

Barzona
Barzona
  • Member since: Jan. 4, 2009
  • Offline.
Forum Stats
Member
Level 13
Game Developer
Response to Keyboard press not registering AS3 2013-08-11 22:49:41 Reply

At 8/11/13 08:47 PM, Diki wrote: I can do it on my Logitech G105 keyboard, so your code works fine.

You'll need to buy a better keyboard if you want it to work for you as well. Though as egg82 pointed out most users won't have a good enough keyboard for it to work, so I wouldn't recommend designing your game around it. One solution could be to let the user define the keys themselves, since it's possible that on their keyboard a different combination will work.

Yeah, letting them decide would be cool. A little overboard for just a little flash game, but I could do it anyway. However, I still need to decide on a decent default setting. Maybe switching to WASD would fix the issue.