UNPKG

use-control

Version:

A powerful set of hooks for elegantly handling keyboard, mouse and gamepad input (soon)

40 lines (39 loc) 1.71 kB
import { MouseButton } from './input/mouse'; export declare function mouseButton(button: MouseButton): { readonly type: "mouse-button"; readonly button: MouseButton; }; export declare function keycode(code: number): { readonly type: "keycode-button"; readonly code: number; }; export declare function gamepadButton(controllerIndex: number, code: number): { readonly type: "gamepad-button"; readonly controllerIndex: number; readonly code: number; }; export declare function mouseAxis(axis: 'x' | 'y'): { readonly type: "mouse-axis"; readonly axis: "x" | "y"; }; export declare function gamepadAxis(controllerIndex: number, axis: number, threshold?: number): { readonly type: "gamepad-axis"; readonly controllerIndex: number; readonly axis: number; readonly threshold: number; }; declare type ButtonAction = ReturnType<typeof mouseButton> | ReturnType<typeof keycode> | ReturnType<typeof gamepadButton>; declare type AxisAction = ReturnType<typeof mouseAxis> | ReturnType<typeof gamepadAxis>; declare type InputMap = { buttons: { [id: string]: ButtonAction[]; }; axes: { [id: string]: AxisAction[]; }; }; export declare function useButtonPressed<T extends InputMap>(inputMap: T, key: keyof T['buttons'], sink: () => void): void; export declare function useButtonReleased<T extends InputMap>(inputMap: T, key: keyof T['buttons'], sink: () => void): void; export declare function useButtonHeld<T extends InputMap>(inputMap: T, key: keyof T['buttons'], intervalMs: number, sink: () => void): void; export declare function useAxis<T extends InputMap>(inputMap: T, key: keyof T['axes'], sink: (v: number) => void): void; export {};