mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
4914116834
* remove recomendation for usage of string type of event * deprecate KEY_DOWN KEY_UP event * support SystemEventType.KEYBOARD_DOWN && SystemEventType.KEYBOARD_UP * deprecate some useless properties * implement keyboard pal * remove SystemEventType toString() update * fix instantiating EventTouch * optimize deprecated info * support native keyboard KEYBOARD_DOWN event * remove usage of event code * fix deprecating pure value properties * optimize deprecating Event type * optimize deprecating getEventCode() update * optimize deprecating eventType * optimize deprecating isPressed * optimize deprecating keybaord event * optimize deprecating rawEvent * Revert "fix deprecating pure value properties" This reverts commit 60d586532496fa1f422f05c54a922b86d1dc96ee. * fix deprecate pure value properties * Revert "fix deprecate pure value properties" This reverts commit a83f1725fedfbd7af445892912aacab8e8502147. * fix deprecating pure value property * update updaate * deprecate some EventType enum in SystemEventType and NodeEventType * optimize * update update * update * update * fix CI * fix CI * fix Circular dependency * fix Circular dependency
270 lines
8.5 KiB
TypeScript
270 lines
8.5 KiB
TypeScript
declare module 'pal/input' {
|
|
interface BaseInputEvent {
|
|
/**
|
|
* Type of the input event used to quickly distinguish between event types.
|
|
*/
|
|
readonly type: import('../../cocos/core/platform/event-manager/event-enum').SystemEventTypeUnion;
|
|
/**
|
|
* Timestamp when the input event is triggered.
|
|
*/
|
|
readonly timestamp: number;
|
|
}
|
|
/**
|
|
* Basic class for all input sources.
|
|
*/
|
|
abstract class BaseInputSource {
|
|
/**
|
|
* Query whether this input source is supported.
|
|
*/
|
|
public readonly support: boolean;
|
|
}
|
|
|
|
interface TouchData {
|
|
/**
|
|
* A unique identifier for this touch.
|
|
* A given touch point will have the same identifier for the duration of its movement around the surface.
|
|
* This lets you ensure that you're tracking the same touch all the time.
|
|
*/
|
|
readonly identifier: number;
|
|
/**
|
|
* The x-coordinate of the touch whose origin is at the bottom-left of the canvas.
|
|
*/
|
|
readonly x: number;
|
|
/**
|
|
* The y-coordinate of the touch whose origin is at the bottom-left of the canvas.
|
|
*/
|
|
readonly y: number;
|
|
/**
|
|
* The amount of pressure being applied to the surface by the user, ranged from 0 to 1.
|
|
*/
|
|
readonly force: number;
|
|
}
|
|
export interface TouchInputEvent extends BaseInputEvent {
|
|
/**
|
|
* Individual points of contact whose states changed between the previous touch event and this one.
|
|
*/
|
|
readonly changedTouches: TouchData[];
|
|
}
|
|
type TouchCallback = (res: TouchInputEvent) => void;
|
|
/**
|
|
* Class designed for touch input.
|
|
*/
|
|
export class TouchInputSource extends BaseInputSource {
|
|
/**
|
|
* Register the touch start event callback.
|
|
* @param cb
|
|
*/
|
|
public onStart (cb: TouchCallback);
|
|
/**
|
|
* Register the touch move event callback.
|
|
* @param cb
|
|
*/
|
|
public onMove (cb: TouchCallback);
|
|
/**
|
|
* Register the touch end event callback.
|
|
* @param cb
|
|
*/
|
|
public onEnd (cb: TouchCallback);
|
|
/**
|
|
* Register the touch cancel event callback.
|
|
* @param cb
|
|
*/
|
|
public onCancel (cb: TouchCallback);
|
|
}
|
|
|
|
export interface MouseInputEvent extends BaseInputEvent {
|
|
/**
|
|
* The x-coordinate of the mouse whose origin is at the bottom-left of the canvas.
|
|
*/
|
|
readonly x: number;
|
|
/**
|
|
* The y-coordinate of the mouse whose origin is at the bottom-left of the canvas.
|
|
*/
|
|
readonly y: number;
|
|
/**
|
|
* The pressed mouse button during the related mouse event.
|
|
* The valid value maybe `EventMouse.BUTTON_LEFT`, `EventMouse.BUTTON_RIGHT` and `EventMouse.BUTTON_MIDDLE`.
|
|
*/
|
|
readonly button: number;
|
|
// this is web only property, should be removed in the futrure.
|
|
movementX?: number;
|
|
movementY?: number;
|
|
}
|
|
type MouseCallback = (res: MouseInputEvent) => void;
|
|
export interface MouseWheelInputEvent extends MouseInputEvent {
|
|
/**
|
|
* The horizontal scroll amount.
|
|
*/
|
|
readonly deltaX: number;
|
|
/**
|
|
* The vertical scroll amount.
|
|
*/
|
|
readonly deltaY: number;
|
|
}
|
|
type MouseWheelCallback = (res: MouseWheelInputEvent) => void;
|
|
/**
|
|
* Class designed for mouse input.
|
|
*/
|
|
export class MouseInputSource extends BaseInputSource {
|
|
/**
|
|
* Register the mouse down event callback.
|
|
* @param cb
|
|
*/
|
|
public onDown (cb: MouseCallback);
|
|
/**
|
|
* Register the mouse move event callback.
|
|
* @param cb
|
|
*/
|
|
public onMove (cb: MouseCallback);
|
|
/**
|
|
* Register the mouse up event callback.
|
|
* @param cb
|
|
*/
|
|
public onUp (cb: MouseCallback);
|
|
/**
|
|
* Register the mouse wheel event callback.
|
|
* @param cb
|
|
*/
|
|
public onWheel (cb: MouseWheelCallback);
|
|
}
|
|
|
|
export interface KeyboardInputEvent extends BaseInputEvent {
|
|
/**
|
|
* Numerical code identifying the unique value of the pressed key.
|
|
*/
|
|
readonly code: number;
|
|
}
|
|
type KeyboardCallback = (res: KeyboardInputEvent) => void;
|
|
/**
|
|
* Class Designed for keyboard input.
|
|
*/
|
|
export class KeyboardInputSource extends BaseInputSource {
|
|
/**
|
|
* Register the key down event callback.
|
|
* @param cb
|
|
*/
|
|
public onDown (cb: KeyboardCallback);
|
|
/**
|
|
* Register the key pressing event callback.
|
|
* NOTE: Compability for the deprecated KEY_DOWN event type. It should be removed in the future.
|
|
* @param cb
|
|
*/
|
|
public onPressing (cb: KeyboardCallback);
|
|
/**
|
|
* Register the key up event callback.
|
|
* @param cb
|
|
*/
|
|
public onUp (cb: KeyboardCallback);
|
|
}
|
|
|
|
/**
|
|
* Class designed for gamepad input
|
|
*/
|
|
export class GamepadInputSource extends BaseInputSource {
|
|
// TODO: add more details for GamepadInputSource class
|
|
}
|
|
|
|
export interface AccelerometerInputEvent extends BaseInputEvent {
|
|
/**
|
|
* The current x value of the accelerometer ranged from -1 to 1.
|
|
*/
|
|
readonly x: number;
|
|
/**
|
|
* The current y value of the accelerometer ranged from -1 to 1.
|
|
*/
|
|
readonly y: number;
|
|
/**
|
|
* The current z value of the accelerometer ranged from -1 to 1.
|
|
*/
|
|
readonly z: number;
|
|
}
|
|
type AccelerometerCallback = (res: AccelerometerInputEvent) => void;
|
|
/**
|
|
* Class designed for accelerometer input
|
|
*/
|
|
export class AccelerometerInputSource extends BaseInputSource {
|
|
/**
|
|
* Asynchronously start the accelerometer.
|
|
* TODO: return a promise.
|
|
*/
|
|
public start ();
|
|
/**
|
|
* Stop the accelerometer.
|
|
* TODO: return a promise.
|
|
*/
|
|
public stop ();
|
|
/**
|
|
* Set interval of the accelerometer callback.
|
|
* The interval is in mileseconds.
|
|
* @param intervalInMileseconds interval in mileseconds
|
|
*/
|
|
public setInterval (intervalInMileseconds: number);
|
|
/**
|
|
* Register the accelerometer change event callback.
|
|
* @param cb
|
|
*/
|
|
public onChange (cb: AccelerometerCallback);
|
|
}
|
|
|
|
/**
|
|
* Class designed for UI input box.
|
|
* TODO: add more description for this class
|
|
*/
|
|
export class InputBox extends BaseInputSource {
|
|
/**
|
|
* Asynchronously show the UI input box, also show the soft keyboard on mobile.
|
|
*/
|
|
public show (): Promise<void>;
|
|
/**
|
|
* Asynchronously hide the UI input box, also hide the soft keyboard on mobile.
|
|
*/
|
|
public hide (): Promise<void>;
|
|
/**
|
|
* Register the UI input box change event callback.
|
|
* @param cb
|
|
*/
|
|
public onChange (cb: ()=>void);
|
|
/**
|
|
* Register the UI input box complete event callback.
|
|
* @param cb
|
|
*/
|
|
public onComplete (cb: ()=>void);
|
|
/**
|
|
* Unregister the UI input box change event callback.
|
|
* @param cb If not specified, all callback would be unregistered.
|
|
*/
|
|
public offChange (cb?: ()=>void);
|
|
/**
|
|
* Unregister the UI input box complete event callback.
|
|
* @param cb If not specified, all callback would be unregistered.
|
|
*/
|
|
public offComplete (cb?: ()=>void);
|
|
}
|
|
|
|
/**
|
|
* Class designed to manage all input sources.
|
|
* TODO: designed `pollEvent()` API
|
|
*/
|
|
class Input {
|
|
public _touch: TouchInputSource;
|
|
public _mouse: MouseInputSource;
|
|
public _keyboard: KeyboardInputSource;
|
|
public _accelerometer: AccelerometerInputSource;
|
|
public _inputBox: InputBox;
|
|
|
|
// public startAccelerometer (): Promise<void>;
|
|
// public stopAccelerometer (): Promise<void>;
|
|
// public setAccelerometerInterval (intercal: number): void;
|
|
|
|
// // input box
|
|
// public showInputBox (): Promise<void>;
|
|
// public hideInputBox (): Promise<void>;
|
|
// public onInputBoxChange (cb: Function); // TODO: don't use Function
|
|
// public onInputBoxComplete (cb: Function);
|
|
|
|
// public pollEvent(): BaseInputEvent | undefined;
|
|
}
|
|
|
|
export const input: Input;
|
|
}
|