I can set a trigger for advancing to the next slide if a user presses ENTER, but I also want to trigger adding "1" to a variable if they press anything other than ENTER.
If you are comfortable using javascript/jquery, you can easily do this by writing a script that takes all input a user enters except 'Enter', and writes to a variable on keypress. The trick here is to isolate the 'Enter' keypress so that it does not get counted along with the others. You could do something like:
$('#searchbox input').bind('keypress', function(e) { if(e.keyCode!=13){ // Enter key not pressed... Trigger counter to variable... } });
Or you can try this alternative:
var code = e.keyCode || e.which; if(code != 13) { //This detects any key presses except the Enter key //Trigger count }
The basic logic is that if a non-Enter key is pressed, it triggers the count, and does nothing when Enter is detected.
A good place to start would be using the configuration seen below:
Since you're setting the trigger to happen when a 'User presses a key', the javascript gets called up whenever this trigger is activated. As you can see in the screen grab, you can set which javascript is used by clicking on the 'Script' selector option. Now the javascript's job is to detect which key was pressed and then send out a variable count when necessary, or do nothing when it detects that the 'Enter' key was pressed.
It may take a lot of trial and error to get working, but hopefully this points you in the right direction.
3 Replies
Hello,
If you are comfortable using javascript/jquery, you can easily do this by writing a script that takes all input a user enters except 'Enter', and writes to a variable on keypress. The trick here is to isolate the 'Enter' keypress so that it does not get counted along with the others. You could do something like:
$('#searchbox input').bind('keypress', function(e) {
if(e.keyCode!=13){
// Enter key not pressed... Trigger counter to variable...
}
});
Or you can try this alternative:
var code = e.keyCode || e.which;
if(code != 13) { //This detects any key presses except the Enter key
//Trigger count }
The basic logic is that if a non-Enter key is pressed, it triggers the count, and does nothing when Enter is detected.
Hope this helps!
Regards,
Joe
Thanks so much, Joe!
How would it function in this context where I want to add 1.0 to variable A any time something other than Enter is pressed?
Hello,
A good place to start would be using the configuration seen below:
Since you're setting the trigger to happen when a 'User presses a key', the javascript gets called up whenever this trigger is activated. As you can see in the screen grab, you can set which javascript is used by clicking on the 'Script' selector option. Now the javascript's job is to detect which key was pressed and then send out a variable count when necessary, or do nothing when it detects that the 'Enter' key was pressed.
It may take a lot of trial and error to get working, but hopefully this points you in the right direction.
Regards,
Joe
This discussion is closed. You can start a new discussion or contact Articulate Support.