I'm in the process of developing a user-friendly method for selecting the trigger key that activates the code. This is what I have so far.
var triggers = {space:"32",enter:"13",tab:"9"};
var triggerKeys = ["space","enter"];
$('input').on('keypress',function(event) {
var unicode= event.keyCode ? event.keyCode : event.which;
if(unicode === triggers[triggerKeys]) {
//code initiation here
}
However, this current setup isn't functioning as intended. Any suggestions on how I can modify it so that the code is activated when any of the keys in the triggerKeys
array are pressed, especially if there are multiple trigger keys?
Currently, the code only works for one trigger key. Should I use a loop to accommodate multiple trigger keys?