Angie
@iamangie
Good morning/afternoon/night, this is my repl.it profile. My name is Angie.
Hello, how do I run a function when a key is pressed in HTML? Thank you
eco27 you can use the addEventListener method:
document.addEventListener("keypress", () => {
console.log("key pressed!")
})
`3 years ago
DynamicSquid Try this:
function detectKey(event)
{
event = event || window.event;
var key = event.key || event.which || event.keyCode;
if (key === 84)
{
doThing();
}
}
Put this under the script tag.3 years ago