ゲーム用の単純なイベント ハンドラーを作成したいのですが、コードは次のとおりです。
$(document).keydown(function(e){
switch(e.keyCode){
case 65: //left (a)
console.log('left');
break;
case 68: //right (d)
console.log('right');
break;
}
});
問題は、キーを押したままにすると、少し後に複数回トリガーされることです。どうすればこの動作を防ぐことができますか? 私はGoogle Chromeでコードを実行しています