Packageorg.MARS.util
Classpublic 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.



Public Methods
 MethodDefined 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
Constructor detail
KeyPoll()constructor
public function KeyPoll(displayObj:DisplayObject)

Constructor

Parameters
displayObj:DisplayObject — a display object on which to test listen for keyboard events. To catch all key events use the stage.
Method detail
isDown()method
public function isDown(keyCode:uint):Boolean

To test whether a key is down.

Parameters
keyCode:uint — code for the key to test.

Returns
Boolean — true if the key is down, false otherwise.

See also

isUp
isUp()method 
public function isUp(keyCode:uint):Boolean

To test whether a key is up.

Parameters
keyCode:uint — code for the key to test.

Returns
Boolean — true if the key is up, false otherwise.

See also

isDown