Packagenet.guttershark.managers
Classpublic final class KeyManager

The KeyManager class simplifies working with keyboard events.



Public Methods
 MethodDefined by
  
addMapping(scope:*, mapping:String, callback:Function, repeatCallbackWhileDown:Boolean = false, repeatWhileDownCallback:Function = null):void
Add a keyboard event mapping.
KeyManager
  
addMappings(objects:Array, mapping:String, callback:Function):void
Add the same mapping and callback to multiple objects.
KeyManager
  
am(scope:*, mapping:String, callback:Function, repeatCallbackWhileDown:Boolean = false, repeatWhileDownCallback:Function = null):void
A shortcut for the addMapping method.
KeyManager
  
[static] Singleton Instance.
KeyManager
  
removeMapping(scope:*, mapping:String):void
Remove a keyboard event mapping.
KeyManager
  
removeMappings(objects:Array, mapping:String):void
Remove the same mapping from multiple objects.
KeyManager
  
rm(scope:*, mapping:String):void
A shortcut for the removeMapping method.
KeyManager
Method detail
addMapping()method
public function addMapping(scope:*, mapping:String, callback:Function, repeatCallbackWhileDown:Boolean = false, repeatWhileDownCallback:Function = null):void

Add a keyboard event mapping.

There are multiple ways you can add a handler. You can add handler for a single character, a word or sentence, or a sequence.

Parameters
scope:* — The scope in which to add the keyboard events to.
 
mapping:String — The mapping to listen for.
 
callback:Function — The callback function.
 
repeatCallbackWhileDown:Boolean (default = false)
 
repeatWhileDownCallback:Function (default = null)

Example
Adding mappings of different types.
 
   km = KeyManager.gi();
   km.addMapping(stage,"f", onF);
   km.addMapping(stage,"Whatup",onWhatup);
   km.addMapping(stage,"CONTROL+SHIFT+M", onM);
   km.addMapping(stage,"CONTROL+m",onM);
   km.addMapping(myTextField,"ENTER",onEnter);
   
   private function onM():void
   {
      trace("on control+shift+m");
   }
   
   private function onF():void
   {
      trace("on f");
   }
   
   private function onWhatup():void
   {
      trace("you typed 'Whatup'");
   }
   
   private function onEnter():void
   {
       trace("you pressed enter in the text field");
   }
   

Supported Key Shortcuts for Key Sequences

addMappings()method 
public function addMappings(objects:Array, mapping:String, callback:Function):void

Add the same mapping and callback to multiple objects.

Parameters
objects:Array — An array of objects to add mappings to.
 
mapping:String — The mapping to listen for.
 
callback:Function — The callback function.
am()method 
public function am(scope:*, mapping:String, callback:Function, repeatCallbackWhileDown:Boolean = false, repeatWhileDownCallback:Function = null):void

A shortcut for the addMapping method.

Parameters
scope:*
 
mapping:String
 
callback:Function
 
repeatCallbackWhileDown:Boolean (default = false)
 
repeatWhileDownCallback:Function (default = null)
gi()method 
public static function gi():KeyManager

Singleton Instance.

Returns
KeyManager
removeMapping()method 
public function removeMapping(scope:*, mapping:String):void

Remove a keyboard event mapping.

Parameters
scope:* — The scope - usually a DisplayObject or Stage.
 
mapping:String — The key event mapping being listened for.

Example
Removing a keyboard event mapping.
 
   var km:KeyboardEventManager = KeyboardEventManager.gi();
   km.addMapping(stage,"f",onF);
   km.removeMapping(stage,"f");
   

removeMappings()method 
public function removeMappings(objects:Array, mapping:String):void

Remove the same mapping from multiple objects.

Parameters
objects:Array — An array of objects to remove the mapping from.
 
mapping:String — The key mapping to remove.
rm()method 
public function rm(scope:*, mapping:String):void

A shortcut for the removeMapping method.

Parameters
scope:*
 
mapping:String