https://github.com/jingwood/js-input-control
A lightweight library to handle the mouse, keyboard and touch control from end-user.
https://github.com/jingwood/js-input-control
input input-control keyboard mouse touches touchscreen ui
Last synced: about 1 year ago
JSON representation
A lightweight library to handle the mouse, keyboard and touch control from end-user.
- Host: GitHub
- URL: https://github.com/jingwood/js-input-control
- Owner: jingwood
- License: mit
- Created: 2020-01-29T13:10:00.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-16T15:18:46.000Z (about 2 years ago)
- Last Synced: 2025-02-28T20:40:57.637Z (over 1 year ago)
- Topics: input, input-control, keyboard, mouse, touches, touchscreen, ui
- Language: JavaScript
- Homepage:
- Size: 359 KB
- Stars: 4
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @jingwood/input-control
A lightweight Javascript library used to handle the input events of mouse, keyboard and touch control from end-user.
# Features
- Event registeriton and dispatching
- Receives and dispatches mouse, keyboard and touch events
- Provides and dispatches dragging events based on mouse and touch events
- Provides functions to check whether specified key is pressed
- Provides hotkey define feature (todo)
# Installation
```shell
yarn add @jingwood/input-control
```
# Hello-World
```js
// get the element to receive mouse, keyboard and touch events
const element = document.getElementById(myTargetElement);
// make sure the element can receive keyboard events
element.tabIndex = 0;
element.focus();
// create controller and use 'on' method to receive input events
const controller = new InputController(element);
// keyup event
controller.on("keyup" e => {
if (e.keyCode === 32) {
alert("Space key was pressed");
}
});
// drag event
controller.on("drag", e => {
console.log("mouse moving " + e.movement.x + ", " + e.movement.y);
});
```
# License
Released under MIT License
Copyright (C) 2015-2020 Jingwood, unvell.com, all rights reserved.