Other Keyboard Events
Other keyboard events in React are:
Event | Occurs When | Description |
---|---|---|
onkeydown | The user presses a key | Used to detect initial keypress |
onkeypress | The user presses a key | It is now deprecated and it represented only character input. |
onkeyup | the user releases a key | Used to detect when a key is released |
React onKeyDown Event
React onKeyDown event occurs on a key press event in a browser. onKeyDown is an updated event in place of onKeyPress.
onKeyPress is now deprecated because it does not work for all keys (like CTRL, SHIFT, and ALT) in all browsers, so onKeyDown is a new event listener that is used to detect the key press event.
It is similar to the HTML DOM onkeydown event but uses the camelCase convention in React.
Syntax:
onKeyDown={keyDownFunction}
Parameter:
- KeyDownFunction: It is a function that will call once any key is pressed from the Keyboard.
Return type:
- KeyboardEvent object that provides information about the keyboard key that was pressed.