Jump to content

altKey combinations not working


Recommended Posts


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>
    function myFunction(e) {

        if(e.altKey && e.key=="a") // option-a is not detected
        else if(e.ctrlKey && e.key=="a") 
            console.log("ctrl-a"); // ctrl-a is not detected
<p>Press ctrl-a inside the text area. Then, press option-a (alt-a) inside the text area.</p>
<textarea id="demo" onkeydown="myFunction(event);"></textarea>


Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...