The KeyboardEvent altKey property in HTML DOM is a read-only property and used to return the boolean value which indicates the alt key is pressed or not. It returns True if alt key is pressed otherwise return false.
Syntax:
event.altKey
Below program illustrates the KeyboardEvent altkey property in HTML:
Example: This example check whether the “ALT” key is pressed or not.
html
<!DOCTYPE html>
< html >
< head >
< title >
HTML DOM KeyboardEvent altKey property
</ title >
</ head >
< body >
< h1 >GeeksforGeeks</ h1 >
< h2 >KeyboardEvent altKey Property</ h2 >
< p >
Check whether the alt key is pressed or not
</ p >
< input type="text" onkeydown="keyboard(event)">
< p id = "test"></ p >
< script >
function keyboard(event) {
var a = document.getElementById("test");
if (event.altKey) {
a.innerHTML = "The ALT key has been pressed!";
}
else {
a.innerHTML = "The ALT key has not been pressed!";
}
}
</ script >
</ body >
</ html >
|
Output:
Before Press the Key:
After Press the key:
Supported Browsers: The browser supported by KeyboardEvent altKey property are listed below:
- Opera 12.1
- Internet Explorer 9
- Google Chrome 1
- Edge 12
- Firefox 1.5
- Apple Safari 1.2
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks 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!
Last Updated :
06 Jul, 2022
Like Article
Save Article