HTML | DOM KeyboardEvent Last Updated : 08 Nov, 2022 Comments Improve Suggest changes Like Article Like Report It refers to the events which occur when a key is pressed on the keyboard. Syntax: <input type="text" onkeypress/onkeydown/onkeyup="function()/event"> Events:The following events occur on pressing a key- onkeydownonkeypressonkeyup Properties: altKey: It returns if alt key was pressed or not.charCode: It returns unicode character of the key.code: It returns the code of the entered key.ctrlKey: It returns if ctrl key was pressed or not.getModifierState(): It returns true if the specified key is activated.isComposing: It returns whether the event is composing or not.key: It returns the key value.keyCode: It returns unicode character of the onkeypress or onkey down event.location: It returns the location of the key on the keyboard.metaKey: It returns if meta key was pressed or not.repeat: It returns if a key is repeatedly holding on.shiftKey: It returns if shift key was pressed or not.which: It returns the unicode character of event type. Return Value: It returns events which occur when a given key is pressed from the keyboard. Example-1: Showing onkeypress event. html <!DOCTYPE html> <html> <body> <h1> <center>Geeks for Geeks </center> </h1> <p>Type something in the box:</p> <input type="text" onkeypress="key()"> <script> function key() { alert("New Key Inserted"); } </script> </body> </html> Output: Before Pressing a key: After Pressing a key: Example-2: Showing onkeydown event. html <!DOCTYPE html> <html> <body> <h1> <center>Geeks for Geeks </center> </h1> <p>Type something in the box:</p> <input type="text" onkeydown="key()"> <script> function key() { alert("New Key Inserted"); } </script> </body> </html> Output: Before Pressing a key: After Pressing a key: Example-3: To check if the pressed key is Alt or not. html <!DOCTYPE html> <html> <body> <h1> <center>Geeks for Geeks </center> </h1> <p>Type something in the box to check if Alt key is pressed or not:</p> <input type="text" onkeydown="isKeyPressed(event)"> <p id="gfg"></p> <script> function isKeyPressed(event) { var x = document.getElementById("gfg"); if (event.altKey) { x.innerHTML = "ALT Key Pressed"; } else { x.innerHTML = "ALT Key Not Pressed"; } } </script> </body> </html> Output: Before Pressing a key: After Pressing a key: Example-4: To find out the pressed key from the keyboard. html <!DOCTYPE html> <html> <body> <h1> <center>Geeks for Geeks </center> </h1> <p>Type something in the box to know the entered key:</p> <input type="text" size="40" onkeydown="myFunction(event)"> <p id="gfg"></p> <script> function myFunction(event) { var x = event.key; document.getElementById( "gfg").innerHTML = "Entered Key is: " + x; } </script> </body> </html> Output: Before Pressing a key: After Pressing a key: Browser Support: The listed browsers support DOM Keyboard Event- Google Chrome 1Mozilla Firefox 1.5Internet Explorer 9Edge 12Safari 1.2Opera 12.1 Comment More infoAdvertise with us Next Article HTML | DOM KeyboardEvent R riarawal99 Follow Improve Article Tags : Web Technologies HTML HTML-DOM Similar Reads HTML DOM KeyboardEvent key Property The keyboardEvent key property in HTML is used to return the value of the key pressed when a key event occurs. It returns a single-character or multi-character string depending on which key is pressed. It is a read-only property. Syntax: event.key Return Value: It returns a string that represents th 1 min read HTML DOM KeyboardEvent code Property The keyboardEvent code property in HTML represents a physical key on the keyboard. It is used to return the key that triggers the event. Syntax: event.code Return Value: It returns a string that represents which key is pressed. Example 1: With KeyDown Event HTML <html> <head> <title 2 min read HTML DOM UiEvent The DOM UiEvent in HTML is an event that is triggered by the user interface belonging to the UiEvent Object. The two main purposes of the UI Event are: Allows registration of event listeners and describes event flow through a tree structure.Provide a common subset of the current event systems used i 2 min read HTML DOM | KeyboardEvent altKey Property 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 1 min read HTML DOM MouseEvent The MouseEvent Object handles events that occur when the mouse interacts with the HTML document. There are lots of events that interacts with the HTML document. Mouse Events: Mouse events are the action taken by the user on the web page, like clicking, hovering over, etc. Mouse Events Description on 3 min read Like