Skip to main content
Participant
February 10, 2009
Answered

Detecting a Key Press

  • February 10, 2009
  • 2 replies
  • 483 views
I am using this code to set up a listener for a key press. I noticed that it works fine when you use a LEFT, RIGHT etc. press, but it will not work with a regular key press(i.e. ctrl+P). It says that there is an undefined property as far as the Letter goes. If anyone can help me with this, I would very much appreciate it.

stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown);

function keyDown(event:KeyboardEvent):void
{
if(event.ctrlKey)
{
var key = event.keyCode;
var P_key = Keyboard.P;
switch(key)
{
case P_key:
trace("this thing works");
break;
}
}
}
This topic has been closed for replies.
Correct answer Lone Star Learning
Ok, I've figured it out. Flash decided to take me for a fool and pretended like it would take the P-key as a press, but in actuality, it only works that way in AIR.

2 replies

Lone Star LearningAuthorCorrect answer
Participant
February 10, 2009
Ok, I've figured it out. Flash decided to take me for a fool and pretended like it would take the P-key as a press, but in actuality, it only works that way in AIR.
kglad
Community Expert
Community Expert
February 10, 2009
what's Keyboard.P?