exemplo1:

<script type=”text/JavaScript”>
$(“#password”).on(‘keyup’, function (e) {
if (e.key === ‘Enter’ || e.keyCode === 13) {
console.log(“Apertou Enter”);
ola();
}
});
</script>
Exemplo2:
<!DOCTYPE html> <html lang="pt-br"> <head> </head> <body onKeyPress="alertkey(event);"> </body> </html> <script> function alertkey(e) { if( !e ) { if( window.event ) { //Internet Explorer e = window.event; } else { return; } } if( typeof( e.keyCode ) == 'number' ) { //DOM e = e.keyCode; } else if( typeof( e.which ) == 'number' ) { //NS 4 compatible e = e.which; } else if( typeof( e.charCode ) == 'number' ) { //also NS 6+, Mozilla 0.9+ e = e.charCode; } else { //total failure, we have no way of obtaining the key code return; } if(e==27) { alert("esc"); } } </script>