document.addEventListener('keydown',test); function test(e){ var x=e.keyCode; if(x == 49){ console.log("hello"); } }