Not yet rated

Problem

When creating a Kiosk application, you normally lock the keyboard away, but there are kiosks where the user needs to input some text, in this case you need to supress keyboard events so that for example the ESC key doesn't work.

Solution

The solution is to prevent the default event being fired from the keyboard eventlistener.

Detailed explanation

All you need to do is attach a Keyboard Event Listener listening for the key_down or key_up event.

stage.addEventListener( KeyboardEvent.KEY_DOWN, killApp, false, 0, true );

After adding the keyboardEventHandler we just need to write the callback method "killApp".

private function killApp( e:KeyboardEvent ):void
{
      e.preventDefault();
      if ( e.keyCode == Keyboard.ESCAPE )
      {
           trace( "The user pressed escape")
           // do something with this.   
      }
}

As you see above the killApp method is preventing any keyboard press ( besides the windows / mac default application shortcuts like CMD+Q or ALT+F4 ).

But if you press the ESC key, you will see the trace appeaer in your trace window.


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes