JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text">

JavaScript

document.querySelector("input").addEventListener("keydown",function(e){
    console.log(e.which);
    if (e.which == 27){
         alert("Escape pressed!");
        return false;
    }
});