Capturing Keyboard Input

Flash can respond to keyboard commands, but when you are working inside Flash, the Flash environment can capture the keyboard input instead of the movie.
When you are testing a Flash movie that uses keyboard input you must:

Start a new Flash ActionScript3 movie and copy the code in the action window.

  stage.addEventListener(KeyboardEvent.KEY_DOWN,  doKeyDown);
  function doKeyDown(e:KeyboardEvent):void {
     trace(e);
  } //doKeyDown 

With the movie running and keyboard shortcuts disabled, type a few keys.
You will notice some useful properties of e, the keyboard event:
e.ctrlKey is true if the control key is held;
e.altKey is true if the ALT key is held;
e.shiftKey is true if the shift key is held.
The other property of e is e.keyCode which we can look at to see which key was pressed.

You can try typing various keys in the movie below:


Get Adobe Flash player

INDEX, Capturing Keyboard Events, Using Keys to Move Object, Keyboard Constants, Combining Keys and Buttons
Next lesson: Drag and Drop

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Capturing Keyboard Events