document.onkeypress=function(e){ var e=window.event || e; if ( 'y' == String.fromCharCode(e.charCode)){ //... } //... }