[KeyboardEventArgs] Include JavaScript properties
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
In a Blazor project, I'm trying to capture information about the keyboard. For example, the end user should be able to navigate through a customized list of items, using the keyboard's up/down arrows. To achieve this, I use the `@onkeydown` event, which returns a `KeyboardEventArgs` object.
But some keyboards have arrows on the NumPad and the codes returned by these keyboards are identical for the number `8` and the `Up arrow`.
Example:
1. Using the separate `Up` arrow
2. By pressing the `Up` arrow on the numeric keypad
3. By pressing the `8` key on the numeric keypad

How to solve that?
### Describe the solution you'd like
In some circumstances, Blazor does not retrieve all the KeyDown information received from JavaScript.
It could be possible to add extra KeyboardEventArgs properties already available in JavaScript... in a similar way to the [JavaScript KeyCode library](https://www.npmjs.com/package/keycode) and to this [demo sample](https://www.toptal.com/developers/keycode).
Interesting properties could be:
- [which](https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/which): The UIEvent.which read-only property of the UIEvent interface returns a number that indicates which button was pressed on the mouse, or the numeric keyCode or the character code (charCode) of the key pressed on the keyboard
- [keyCode](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode): The KeyboardEvent.keyCode read-only property represents a system and implementation dependent numerical code identifying the unmodified value of the pressed key.
- [charCode](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/charCode): The charCode read-only property of the KeyboardEvent interface returns the Unicode value of a character key pressed during a keypress event.
⚠️ The main problem (and probably the reason for the non-existence of these properties in `KeyboardEventArgs`) is that all 3 are declared as **Obsolete**.
But
1. They've been implemented and still exist in all browsers for years.
2. Like the JavaScript libraries presented above, they remain the only way to get information about the "real" keyboard key pressed by the user.
It might be a good idea to add these three properties to `KeyboardEventArgs` and flag them `Obsolete` to warn the developer of any potential risks.
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.