var cache = ""; window.onkeypress = function (e) { if (e.keyCode == 13) alert(cache); else cache += String.fromCharCode(e.keyCode); };