I am trying to embed my JavaScript code in to a StoryLine Scorm course.
I need to change the variable KeyPressed_WrongKey if user click any key except "Alt" or "=".
My JavaScript code looks like this.
var player = GetPlayer();
var isPressedCtrl = 0;
$(document).keyup(function (e) {
if (e.which == 18) isPressedCtrl=0;
}).keydown(function (e) {
if (e.which == 18) isPressedCtrl=1;
if (e.which == 187 && isPressedCtrl == 1) {
player.SetVar("KeyPressed", 1); //run if Alt+= pressed
}
if (e.which != 187 || e.which != 18) {
player.SetVar("KeyPressed_WrongKey", 1); //run if pressed anything else
}
});
When I press Alt or =, the second IF is true too...
Can anybody help with this?
How can I correct the script for pressing any key except what is needed?
More of a suggestions than a solution. That is, to drop
e.whichand usee.codeinstead.Why? Because
whichis deprecated andcodeis easy to read without the need for looking up what the number means.Also, your question does not seem to match your code. The logic seems to be all over the place compared to the question.
If my understanding is correct, you can replace most of your code with one line.