Sunday, January 25, 2026
HomeLanguagesJavascriptHow to detect Alt/Option + another key in textarea ?

How to detect Alt/Option + another key in textarea ?

In this article, we need to Detect Alt/Option + another key in textarea by using HTML and JavaScript. It detects both the keys i.e. Alt + h. The onkeydown Event occurs when someone presses a key (on the keyboard).

Syntax:

<textarea onkeydown="newScript" >

Example: The below code illustrates to detect that when the user pressed the Alt + h keys on the textarea. It will produce an alert message.

HTML




<body>
    <h1 style="color:green">
        GeeksForGeeks
    </h1>
      
    <h2>
        How to detect Alt/Option +
        another key in textarea?
    </h2>
      
    <textarea onkeydown="myFunction(event);"></textarea>
      
    <script>
        function myFunction(e) {
          
            // It check both  altKey + 'A' or 'a' 
            if (e.altKey && e.key === "h") {
                alert(
            "neveropen says Detection successfully ");
            }
        }
    </script>
</body>


Note: We can also use ASCII code for detecting the keys. 

Output:

 

Supported Browsers are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32475 POSTS0 COMMENTS
Milvus
122 POSTS0 COMMENTS
Nango Kala
6847 POSTS0 COMMENTS
Nicole Veronica
11978 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12065 POSTS0 COMMENTS
Shaida Kate Naidoo
6986 POSTS0 COMMENTS
Ted Musemwa
7221 POSTS0 COMMENTS
Thapelo Manthata
6934 POSTS0 COMMENTS
Umr Jansen
6912 POSTS0 COMMENTS