Inspired by captaincomic's Keyboard Input scene behavior (
http://community.stencyl.com/index.php/topic,24713.msg141968.html#msg141968), for me this works:
Create a scene behavior and add it to the first scene.
Import block
------------
import nme.events.Event;
import nme.events.KeyboardEvent;
import nme.Lib;
import nme.ui.Keyboard;
When created block
-------------------
in a code block:
var lastEvent:KeyboardEvent;
Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, function(event) {
lastEvent = event;
// trace("Keydown: " + lastEvent.keyCode);
if (lastEvent.keyCode==27) {
lastEvent.stopImmediatePropagation();
lastEvent.stopPropagation();
// call your function here
sayToScene("Global Functions Scene", "ControlBackButton", [getCurrentSceneName()]);
}
});
Lib.current.stage.addEventListener(KeyboardEvent.KEY_UP, function(event) {
lastEvent = event;
// trace("Keyup: " + lastEvent.keyCode);
if (lastEvent.keyCode==27) {
lastEvent.stopImmediatePropagation();
lastEvent.stopPropagation();
}
});