document.onkeypress=function(e){ var key=(window.event)?e.keyCode:e.which,keyChar=String.fromCharCode(key); if(keyChar=="x" || keyChar=="X") alert("Es x"); }