Trying to detect altKey combinations in a text area, but it's not working. In the following example, the code detects ctrl-a, but not alt-a. Why?
<!DOCTYPE html><html><head><script>function myFunction(e){if(e.altKey && e.key=="a")// option-a is not detected
console.log("alt-a");elseif(e.ctrlKey && e.key=="a")
console.log("ctrl-a");// ctrl-a is not detected}</script></head><body><p>Press ctrl-a inside the text area. Then, press option-a (alt-a) inside the text area.</p><textareaid="demo"onkeydown="myFunction(event);"></textarea></body></html>
altKey combinations not working
in JavaScript
Posted
Hi,
Trying to detect altKey combinations in a text area, but it's not working. In the following example, the code detects ctrl-a, but not alt-a. Why?