var str = "" document.addEventListener("keydown", function(e){ console.log(e.keyCode) var ENTER = 13 if(e.keyCode == ENTER){ console.log(str) str = "" return; } str += e.key },false)