/**Uso. *KeyboardWatcher.addKeyObserver(int tecla , function Callback); */ KeyboardWatcher.addKeyObserver(73,_doInsert);//on ‘I’ , of ‘insert’ KeyboardWatcher.addKeyObserver(67,_doCalculate);//on ‘C’ , of ‘Calculate’ //Code. package core.insania.appmanager{ import flash.events.KeyboardEvent; import flash.ui.Keyboard; import mx.collections.ArrayCollection; import mx.controls.Alert; /** * * @author XD * */ public final class KeyboardWatcher{ /** * */ public static var listeners:ArrayCollection= new ArrayCollection; /** * * @param $keyCode * @param fncCallback * */ static public function addKeyObserver($keyCode:int,fncCallback:Function):void{ KeyboardWatcher.listeners.addItem( {’keyCode’:$keyCode,’callback’:fncCallback} ); } /** * * @param $event * */ static public function delegate($event:KeyboardEvent):void{ /* if ($event.keyCode == Keyboard.SHIFT) Alert.show(”Shift”); if ($event.keyCode == Keyboard.CONTROL)Alert.show(”Ctrl”); */ //Alert.show(”Key Pressed: ” + String.fromCharCode($event.charCode) + ” (key code: ” + $event.keyCode + ” character code: ” + $event.charCode + “)”); if(String($event.target).indexOf(’UITextField’)==-1)// no nos interesa si esta escribiendo en un texfield for(var s:String in KeyboardWatcher.listeners)//Loop para encontrar el keyCode adecuado if($event.keyCode===KeyboardWatcher.listeners[s].keyCode&&KeyboardWatcher.listeners[s].callback!=null) (KeyboardWatcher.listeners[s].callback)();//callback } } }