Javascript examples for DOM:Key Event
The altKey property tells if the "ALT" key is pressed.
This property is read-only.
A Boolean, telling if the "ALT" key was pressed.
The following code shows how to find out if the "ALT" key was pressed when a keyboard key is pressed:
<!DOCTYPE html> <html> <body> <input type="text" onkeydown="isKeyPressed(event)"> <p id="demo"></p> <script> function isKeyPressed(event) {/*from w ww.j av a 2 s . co m*/ var x = document.getElementById("demo"); if (event.altKey) { x.innerHTML = "The ALT key was pressed!"; } else { x.innerHTML = "The ALT key was NOT pressed!"; } } </script> </body> </html>