7 Replies - 2352 Views - Last Post: 21 June 2012 - 05:32 AM

#1 jay1459  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-November 10

Keyboard events not getting all keys AS3

Posted 07 June 2012 - 10:44 AM

So I have a problem, approximately half the keys on my keyboard are not traced, including the A, S and Return keys required by the game I am writing, here is the keyDownListener function, I am almost certain the actual code is correct, but am hoping someone can enlighten me on an error or of a problem with flash that causes this



function keyDownListener(e:KeyboardEvent):void
{
	trace(e.keyCode)
	
	if(e.keyCode == LEFT)
	{
		keyPressedLeft = true;
	}
	
	if(e.keyCode == UP)
	{
		keyPressedUp = true;
	}
	
	if(e.keyCode == RIGHT)
	{
		keyPressedRight = true;
	}
	
	if(e.keyCode == DOWN)
	{
		keyPressedDown = true;
	}
	
	if(e.keyCode == W)
	{
		keyPressedW = true;
	}
	
	if(e.keyCode == A)
	{
		keyPressedA = true;
	}
	
	if(e.keyCode == S)
	{
		keyPressedS = true;
	}
	
	if(e.keyCode == D)
	{
		keyPressedD = true;
	}
	
	if(e.keyCode == RETURN)
	{
		keyPressedReturn = true;
	}
}



Is This A Good Question/Topic? 0
  • +

Replies To: Keyboard events not getting all keys AS3

#2 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: Keyboard events not getting all keys AS3

Posted 07 June 2012 - 10:51 AM

What are the values of LEFT,W etc?

Have you tried using if(e.KeyCode == Keyboard.LEFT)
Was This Post Helpful? 0
  • +
  • -

#3 jay1459  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-November 10

Re: Keyboard events not getting all keys AS3

Posted 07 June 2012 - 11:13 AM

space is one of the keys that works which is why return is missing and space has been replaced, Return was 32. the constants represent the keys value according to flash.

var keyPressedLeft:Boolean;
var keyPressedUp:Boolean;
var keyPressedRight:Boolean;
var keyPressedDown:Boolean;

var keyPressedW:Boolean;
var keyPressedA:Boolean;
var keyPressedS:Boolean;
var keyPressedD:Boolean;

var keyPressedSpace:Boolean;

const LEFT = 37;
const UP = 38;
const RIGHT = 39;
const DOWN = 40;

const W = 87;
const A = 65;
const S = 83;
const D = 68;

const SPACE = 32;


Was This Post Helpful? 0
  • +
  • -

#4 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: Keyboard events not getting all keys AS3

Posted 07 June 2012 - 11:16 AM

When you press a key and trace the e.keyCode(), what values are you getting?

For example when you hit the left arrow, what keycode is displayed?
Was This Post Helpful? 0
  • +
  • -

#5 jay1459  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-November 10

Re: Keyboard events not getting all keys AS3

Posted 07 June 2012 - 11:22 AM

Apologies, Return Key was 13 Not 32

All the correct keycodes are displaying however, not all the keys are being tracked, for example, i require W,A,S,D, Return, Up Left Down and Right, all but A and S are got by flash when traced, on further analysis, i discovered that approx half of the keys are not got when i do:
trace(e.keyCode) 


Here is where my problem lies

87
85
68
71
88

in fact when traced, only these 5 keys appear in console after pressing all the alphabet only
Was This Post Helpful? 0
  • +
  • -

#6 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: Keyboard events not getting all keys AS3

Posted 07 June 2012 - 11:24 AM

Hang on so you mean the keyCode is not what you think it should be or the trace is not even being executed?

You don't have a strange international keyboard do you?
Was This Post Helpful? 0
  • +
  • -

#7 jay1459  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-November 10

Re: Keyboard events not getting all keys AS3

Posted 07 June 2012 - 11:28 AM

Normal Dell qwerty Keyboard, the problem is the keys are not being picked up by flash at all, with trace(e.keyCode) all key presses should be output to console, so why am a missing most of the alphabet? sorry, im new if you couldnt tell :) but no matter what, tracing that should output all keypresses
Was This Post Helpful? 0
  • +
  • -

#8 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 999
  • View blog
  • Posts: 4,175
  • Joined: 14-February 08

Re: Keyboard events not getting all keys AS3

Posted 21 June 2012 - 05:32 AM

This works fine for me:s which keys are missing?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1