1.35.0 • Published 2 years ago

inp v1.35.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Inp

State based input library for the browser.


Installation:

Either install with npm or use a CDN such as unpkg (eg. https://unpkg.com/inp/index.js).

Usage:

import InputReader from 'path/to/inp.js';

let input = InputReader();
const frameRate = 1000/60;
function main() {
	/* input.down tells you if that button is down in the current frame / step. */
	if(input.down('a')) console.log('Key "A" pressed!');
	/* input.up does much the same as input.down but instead tells you if the button was released this frame */
	if(input.up('MouseLeft')) console.log('Left Mouse Button was released this timestep.');
	/* use input.mouse to get the position of the mouse this frame */
	console.log(input.mouse('x'), input.mouse('y'));
	console.log(input.mouse().x, input.mouse('both').y);
	/* and input.step at the end of you main loop to step forward. Nothing will work unless you do this. */
	input.step();
	setTimeout(main, frameRate);
}
main();

API:

InputReader.down(key: string): boolean

Takes in a string that is either a valid event.key, "MouseLeft", "MouseRight", "MouseMiddle", "MouseBack", or "MouseForward". Returns a boolean of whether it's down.


InputReader.up(key: string): boolean

Similar InputReader.down, tells you if a key has been released this timestep, takes the same arguments as InputReader.down.


InputReader.mouse(which?: string): number | Object

Takes in a string that is either "x", "y", or "both", returns the X position of the mouse, the Y position of the mouse, or {x: <number>, y: <number>}, respectively. If no argument is given it defaults to "both".


InputReader.step(): void

Steps forward once and updates everything. Required to be called before any inputs can be read correctly.


(:

1.35.0

2 years ago

1.34.0

2 years ago

1.33.0

2 years ago

1.32.0

2 years ago

1.30.0

2 years ago

1.29.0

2 years ago

1.28.0

2 years ago

1.27.0

2 years ago

1.26.0

2 years ago

1.25.0

2 years ago

1.24.0

2 years ago

1.23.0

2 years ago

1.20.0

2 years ago

1.19.0

2 years ago

1.18.0

2 years ago

1.17.0

2 years ago

1.16.0

2 years ago

1.15.0

2 years ago

1.14.0

2 years ago

1.13.0

2 years ago

1.12.0

2 years ago

1.11.0

2 years ago

1.10.0

2 years ago

1.9.0

2 years ago

1.7.0

2 years ago

1.6.0

2 years ago

1.3.1

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago