keycode
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Keycode is a popular package on npm which provides a simple map of keyboard codes, allowing developers to easily convert between keyboard keycodes and key names, and vice versa. It is capable of intelligently determining what you're trying to accomplish based on the type of argument you supply. This means the keycode package can give you the name of the key associated with an event, return the lowercase name of a given numeric keycode, or provide the numeric keycode for a given key name. Built with a determination to simplify the process of keyboard event handling in your coding projects, keycode is a versatile tool for JavaScript developers.
The installation of keycode can be achieved through npm or component. To install it using npm, use the command npm install keycode
. For component, use component install timoxley/keycode
. Once installed, you can require the keycode package in your JavaScript file using var keycode = require('keycode');
.
Usage examples:
//Listen for keydown event and log the name of the key pressed
document.addEventListener('keydown', function(e) {
console.log("You pressed", keycode(e))
})
//Retrieve the name of the key by providing the numeric keycode
console.log(keycode(13)) //Outputs: 'enter'
//Log the numeric keycode by providing the name of the key
console.log(keycode('Enter')) //Outputs: 13
//Note: keycode is not case sensitive
//Test if a keyboard event matches a given name or keycode
keycode.isEventKey(event, 'enter') //Output: true if 'Enter' key was pressed
keycode.isEventKey(event, 13) //Output: true if 'Enter' key was pressed
The documentation for the keycode package can be found directly on its GitHub page. This includes a list of all current APIs, descriptions of what each one does, and examples of how to use them. The GitHub page also provides access to the package's source code, enabling developers to dig deeper into its workings as needed, contributing to its continuous development and the overall advancement of the JavaScript community. More in-depth usage descriptions, privacy policies, guides, and collaborations with the community can also be found there. Make sure to check it out for comprehensive details about the keycode package.