I want to trigger a javascript function whenever a specific key is pressed on the keyboard, for example
After pressing button "A" on the keyboard, run the function "myFunction()"
function myFunction() {
alert("hey");
}
I want to trigger a javascript function whenever a specific key is pressed on the keyboard, for example
After pressing button "A" on the keyboard, run the function "myFunction()"
function myFunction() {
alert("hey");
}
Something similar
<script>
document.addEventListener("keydown", event => {
if (event.isComposing || event.keyCode !== 65) {
return;
}
myFunction();
});
function myFunction() {
alert("hey");
}
</script>