Javatpoint Logo
Javatpoint Logo

Javascript getModifierState() KeyboardEvent Method

Javascript getModifierState() KeyboardEvent uses to know which keypresses are on the keyboard. The event returns true if modifiers keys are pressed or clicked off the keyboard. We can use the pressed, clicked key, and the keyboard event activates the function.

Syntax

The syntax uses the javascript tag to use getModifierState() KeyboardEvent.

Description: Modifier_key is used to press or click the keyboard button.

Key pressed modifiers

Modifier keys work or are triggered when it is activated by pressing down:

  • Alt
  • Shift
  • AltGraph
  • Control
  • Meta

Key clicked modifiers

Modifier keys work or are triggered when it is clicked and deactivated:

  • NumLock
  • CapsLock
  • ScrollLock

Examples

The following examples show the getModifierState() KeyboardEvent with methods.

Example 1:

The example shows which key is pressed from the keyboard and shows event information. We can use other keyboard events and javascript functions to get event information. The keyboard press event shows and operates the alt key button.

Output

The keydown event shows alt keys functionality.

Javascript getModifierState() KeyboardEvent Method

Example 2:

The example shows which key is pressed from the keyboard and shows shift event information. If the shift key is pressed down, the output shows true otherwise false. The keyboard event shows and operates the shift press button.

Output

The keydown event shows alt keys functionality.

Javascript getModifierState() KeyboardEvent Method

Example 3:

The example shows which key onclick from the keyboard and shows number lock event information. The keyboard event shows and operates the numlock button.

Output

The keydown event shows alt keys functionality.

Javascript getModifierState() KeyboardEvent Method

Example 4

The example shows which key is down from the keyboard and shows capslock events information. The keyboard event shows and operates the capslock button.

Output

The keydown event shows alt keys functionality.

Javascript getModifierState() KeyboardEvent Method

Conclusion

The getModifierState keyboard event works when the particular key operates with the function for the user interactive functionality. The key function works with the web page's up, down, and Press events.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA