Be a Supporter!

charCode for arrow keys trace as 0

  • 88 Views
  • 2 Replies
New Topic Respond to this Topic
Brossting
Brossting
  • Member since: Jun. 6, 2011
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
charCode for arrow keys trace as 0 2014-04-09 20:34:12 Reply

Hey, this is my first post so forgive me if I leave anything out,

I've got a KEY_DOWN event that checks the charCode of a pressed key, I need the event to check for left and right arrow keys. So within I write:

if (e.charCode == 37){
slowDown();
}else if (e.charCode == 39){
speedUp();
}

This method works for other keys and their respective charCodes but doesn't for these, so I check what it wants with:

trace(e.charCode);

pressing enter, space, letter keys etc. all trace their corresponding charCodes but the arrow keys output as 0. Am I missing something? Is there a specific event for the arrow keys instead?

Thanks, Brossting

Sam
Sam
  • Member since: Oct. 1, 2005
  • Offline.
Forum Stats
Moderator
Level 19
Programmer
Response to charCode for arrow keys trace as 0 2014-04-09 20:43:52 Reply

You want to compare the value of:

e.keyCode
Brossting
Brossting
  • Member since: Jun. 6, 2011
  • Offline.
Forum Stats
Member
Level 04
Blank Slate
Response to charCode for arrow keys trace as 0 2014-04-09 20:51:15 Reply

That was pretty damn simple, thank you.

At 4/9/14 08:43 PM, Sam wrote: You want to compare the value of:

e.keyCode