Posted By

adrianparr on 02/10/10


Tagged

input type space key user controls up down keyboard press interaction as3


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tspitzr


AS3 Detecting key presses


 / Published in: ActionScript 3
 

Use this to detect key presses and respond to them.

  1. import flash.ui.Keyboard;
  2. import flash.events.KeyboardEvent;
  3.  
  4. stage.addEventListener(KeyboardEvent.KEY_DOWN, onStage_KEY_DOWN);
  5. stage.addEventListener(KeyboardEvent.KEY_UP, onStage_KEY_UP);
  6.  
  7. function onStage_KEY_DOWN(event:KeyboardEvent):void
  8. {
  9. trace("onStage_KEY_DOWN");
  10. if (event.keyCode == Keyboard.SPACE) {
  11. trace("Keyboard.SPACE");
  12. }
  13. }
  14.  
  15. function onStage_KEY_UP(event:KeyboardEvent):void
  16. {
  17. trace("onStage_KEY_UP");
  18. if (event.keyCode == Keyboard.SPACE) {
  19. trace("Keyboard.SPACE");
  20. }
  21. }

Report this snippet  

You need to login to post a comment.