Skip to content
Related Articles

Related Articles

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

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 23 Aug, 2020

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


<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 the alert message.


<!DOCTYPE html>
        How to detect Alt/Option +
        another key in textarea?
    <textarea onkeydown="myFunction(event);">
        function myFunction(e) {
            // It check both  altKey + 'A' or 'a' 
            if (e.altKey && e.key === "h") {
    "GeeksforGeeks says Detection successfully ");

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

  • Before pressing on Alt + h Keys:
  • After pressing on Alt + h Keys

Supported Browsers are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!