PIONEER'S PRO TIPS: Scripting keyboard trigger

Hey, I would like to share with you a way to make any keystroke into a trigger.

With the following script you will be able to program an event whenever a particular key is pressed. Meaning you can add as many events as you want triggered by different keys. For example a key to show or hide specific objects or a key to start the animation. 

It can come quite useful when doing presentations because you can have full control of when certain events are triggered.

Enjoy the Quick Tip 

var TriggerEventClass = function () {
    EP.Event.call(this);
};

TriggerEventClass.prototype = Object.create(EP.Event.prototype);
TriggerEventClass.prototype.constructor = TriggerEventClass;
TriggerEventClass.prototype.type = 'TriggerEventType';

if (STU.TriggerEvent === undefined)
    STU.TriggerEvent = TriggerEventClass;

if (EP.EventServices.getEventByType('TriggerEventType') === undefined)
    EP.EventServices.registerEvent(TriggerEventClass);

beScript.onStart = function () {

};

beScript.onStop = function () {
    //Will be called on experience stop.
};

beScript.execute = function (context) {
    //Will be called on each frame.
    //To access last frame duration, use 'context.deltaTime'.
    //Insert your code here.
};

beScript.onAllKeyboardRelease = function (iEvent) {
    //console.log(iEvent.key); //remove comment to debug
    if (iEvent.key == this.KeyCode) {
        var newEvent = new STU.TriggerEvent();
        this.actor.dispatchEvent(newEvent);
    }
};