Alert some text if the user presses the "A" key.
Press the "A" key on the keyboard in the input field to alert some text.
<!DOCTYPE html> <html> <body> <input type="text" size="40" onkeydown="myFunction(event)"> <p id="demo"></p> <script> function myFunction(event) {/*from ww w . j a va 2s . co m*/ var x = event.key; // If the pressed keyboard button is "a" or "A" (using caps lock or shift), alert some text. if (x == "a" || x == "A") { document.getElementById("demo").innerHTML = "You pressed the 'A' key!"; } } </script> </body> </html>