Trigger to capture wrong key press

Jun 19, 2020

Hi,

 

I am building a course which requires users to press the enter key. However if they select any other key I need an incorrect layer to show.

 

Is anyone aware of a way to encapsulate all other keyboard buttons in a trigger?

 

Thanks!

Christina

5 Replies
Sam Hill

Hi Christina, unfortunately not. There is no IF/ELSE in Storyline. I would recommend looking to JavaScript for this solution as you would be able to program more efficiently. You can then communicate a result back to a Storyline variable called "enterpressed" to a value of either "Y" or "N" and show the feedback you would like. Make sure "enterpressed" has a value of "" to being with so you can detect a variable value change to either "Y" or "N".

Here's the JavaScript.

var player = GetPlayer();
document.addEventListener("keypress",function(e){
player.SetVar("enterpressed",(e.keyCode == 13 ? "Y" : "N"))
});

As mentioned, have a trigger that is looking for a variable change on "enterpressed" with an IF statement. If "enterpressed" = "Y" then enter key was pressed. Have another event looking for the value "N".

Hope that makes some sense?

This discussion is closed. You can start a new discussion or contact Articulate Support.