public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER){
// Do something
}
}
document.getElementById("yourElementId").addEventListener("keypress", function (event) {
if (event.key === "Enter") {
// the code you want to run
}
})