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 post
Share on other sites
  • 2 weeks later...
  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...