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);
}
Thanx in advance..
Try keyup:
Try this:
Use keydown and keyup events only. They work as their name implies, keydown : a single event when a key is pressed. keyup - a single event when the key is released.