Listening+to+the+Keyboard


 * What do you need to import into your .as file to listen to the keyboard?**

code format="actionscript3" package {   import flash.events.*; import flash.ui.Keyboard; ... code


 * What is the syntax for setting up an EventListener for the Keyboard?**

code format="actionscript3" public function GenericConstructor {   stage.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyPress); } code

code format="actionscript3" public function handleKeyPress(kEvt: KeyboardEvent) code
 * The EventListener will call another function, like "handleKeyPress."**
 * In this function, how can you tell which button was pressed?**

code format="actionscript3" public function handleKeyPress(kEvt: KeyboardEvent) {   if(kEvt.KeyCode==Keyboard.LEFT) trace("you pressed the left arrow key"); } code You can find all the constants for keys if you type "Keyboard." and scroll through the window. Note that not all of the options in the window are necessarily key constants.


 * What types of keyboard events are there?**

There is Keyboard.KEY_DOWN and Keyboard.KEY_UP. The former is for keys that are pressed and the latter is for keys that are released.