An open API service indexing awesome lists of open source software.

https://github.com/alima-webdev/keystroke-input

Keystroke Input Element
https://github.com/alima-webdev/keystroke-input

custom-elements form html input webcomponents

Last synced: 3 months ago
JSON representation

Keystroke Input Element

Awesome Lists containing this project

README

        

# Keystroke Input Element
A custom input element that handles keystrokes. Created as a custom HTML element using Web Components.

## Installation

### Using NPM
To install this custom input element in your project, use the npm command:

```bash
npm install keystroke-input
```

Import it into your javascript file
```javascript
import "keystroke-input"

...
```

### Without NPM

Clone the Github repository into your project's directory

```bash
git clone https://github.com/alima-webdev/keystroke-input.git
```

Add the input tag and javascript file to your project's HTML file
```html

```

## Usage
Listen to the keystrokechange event to obtain the user's keystroke
```javascript
document.getElementById("keystroke").addEventListener("keystrokechange", (event) => {
const keystroke = event.detail.keystroke
...
})
```

The keystroke object is formatted as:
```javascript
{
modifiers: {
alt: boolean,
ctrl: boolean,
meta: boolean,
shift: boolean
},
key: string
}
// It also contains the functions toString(), toJSON(), and validateAgainst(event: KeyboardEvent)
```

## License
This project is released under the GNU GENERAL PUBLIC license. See the [LICENSE](./LICENSE) file for more details.