| Package | org.MARS.util |
| Class | public class KeyPoll |
Games often need to get the current state of various keys in order to respond to user input. This is not the same as responding to key down and key up events, but is rather a case of discovering if a particular key is currently pressed.
In Actionscript 2 this was a simple matter of calling Key.isDown() with the appropriate key code. But in Actionscript 3 Key.isDown no longer exists and the only intrinsic way to react to the keyboard is via the keyUp and keyDown events.
The KeyPoll class rectifies this. It has isDown and isUp methods, each taking a key code as a parameter and returning a Boolean.
| Method | Defined by | ||
|---|---|---|---|
|
KeyPoll(displayObj:DisplayObject)
Constructor
| KeyPoll | ||
|
isDown(keyCode:uint):Boolean
To test whether a key is down.
| KeyPoll | ||
|
isUp(keyCode:uint):Boolean
To test whether a key is up.
| KeyPoll | ||
| KeyPoll | () | constructor |
public function KeyPoll(displayObj:DisplayObject)Constructor
ParametersdisplayObj:DisplayObject — a display object on which to test listen for keyboard events. To catch all key events use the stage.
|
| isDown | () | method |
public function isDown(keyCode:uint):BooleanTo test whether a key is down.
ParameterskeyCode:uint — code for the key to test.
|
Boolean — true if the key is down, false otherwise.
|
See also
| isUp | () | method |
public function isUp(keyCode:uint):BooleanTo test whether a key is up.
ParameterskeyCode:uint — code for the key to test.
|
Boolean — true if the key is up, false otherwise.
|
See also