I am trying to get keys from users using Javascript and storing it in a Javascript object.
i.e. when I press A, 1 should be added to myJSON[65].
The following code works perfectly but if users press a key for a long time it will detect it as multiple key presses. I don’t wan’t that. Is there a better way to do this?
var myJSON={65:[],83:[],68:[],70:[],71:[]};
window.onkeydown=function(e){
console.log(myJSON);
myJSON[parseInt(e.keyCode)].push(1);
}
Try this: