mirror of
https://github.com/motajs/template.git
synced 2026-10-23 08:01:48 +08:00
feat: 完善按键系统接口
This commit is contained in:
parent
6015628d9b
commit
ddbc2825c4
@ -12,7 +12,9 @@ export const enum HotkeyEmitMode {
|
||||
/** 只会触发一次 */
|
||||
Once,
|
||||
/** 按下后依据激励源进行触发 */
|
||||
Excited
|
||||
Continuous,
|
||||
/** 按下后节流触发 */
|
||||
Throttle
|
||||
}
|
||||
|
||||
export interface IHotkeyEmitContext {
|
||||
@ -46,6 +48,14 @@ export interface IHotkeyEmitInfo {
|
||||
export interface IHotkeyCommand {
|
||||
/** 当前指令可以被多少种按键组合触发 */
|
||||
readonly length: number;
|
||||
/** 按键触发方式 */
|
||||
readonly mode: HotkeyEmitMode;
|
||||
/** 首次触发与第二次触发的最小时间间隔 */
|
||||
readonly interval: number;
|
||||
/** 按下后距离第一次触发的最小时间间隔 */
|
||||
readonly timeout: number;
|
||||
/** Throttle 模式下,两次触发之间的最小时间间隔 */
|
||||
readonly dt: number;
|
||||
|
||||
/**
|
||||
* 设置此按键组合数量,如果小于当前值,会导致某些按键触发组合被删除
|
||||
@ -72,18 +82,36 @@ export interface IHotkeyCommand {
|
||||
iterateKeyCombinations(): Iterable<[index: number, key: KeyCode[]][]>;
|
||||
|
||||
/**
|
||||
* 按下时只触发一次,不会连续触发
|
||||
* 按下后,在经过 `timeout` 时间后只触发一次,不会连续触发
|
||||
* @param timeout 按下后距离首次触发的时间间隔,单位毫秒,默认为 0
|
||||
*/
|
||||
once(): void;
|
||||
once(timeout?: number): void;
|
||||
|
||||
/**
|
||||
* 当按下后立刻进行一次触发,之后在松开前,会按照激励源的激励触发
|
||||
* @param excitation 触发激励源
|
||||
* @param interval 第一次触发距离第二次触发的最小时间间隔,设置后,按下时会立刻进行一次触发,
|
||||
* 而第二次触发需要等待 `interval` 毫秒才会触发。默认为 0
|
||||
* @param timeout 按下后距离首次触发的时间间隔,单位号码,默认为 0
|
||||
*/
|
||||
continuous(excitation: IExcitation<unknown>): void;
|
||||
continuous(interval?: number, timeout?: number): void;
|
||||
|
||||
/**
|
||||
* 当按下后立刻进行一次触发,之后在松开前,会根据激励源的激励进行触发,两次触发的触发间隔不小于节流间隔
|
||||
* @param dt 节流间隔
|
||||
* @param interval 第一次触发距离第二次触发的最小时间间隔,设置后,按下时会立刻进行一次触发,
|
||||
* 而第二次触发需要等待 `interval` 毫秒才会触发。默认为 0
|
||||
* @param timeout 按下后距离首次触发的时间间隔,单位号码,默认为 0
|
||||
*/
|
||||
throttle(dt: number, interval?: number, timeout?: number): void;
|
||||
}
|
||||
|
||||
export interface IHotkeySystem {
|
||||
/**
|
||||
* 设置当前按键系统由指定激励源所激励,用于连续触发按下后持续触发等触发场景
|
||||
* @param excitation 激励源
|
||||
*/
|
||||
excitedBy(excitation: IExcitation<number>): void;
|
||||
|
||||
/**
|
||||
* 进入新的按键作用域
|
||||
*/
|
||||
@ -121,10 +149,24 @@ export interface IHotkeySystem {
|
||||
implement(command: string, func: (ctx: IHotkeyEmitContext) => void): void;
|
||||
|
||||
/**
|
||||
* 触发指定按键命令
|
||||
* 手动触发指定按键命令
|
||||
* @param command 按键指令标识符
|
||||
* @param context 按键的上下文信息
|
||||
* @returns 是否执行成功,如果按键命令不存在或上下文条件无法触发指定按键指令,会返回 `false`
|
||||
*/
|
||||
emit(command: string, context: IHotkeyEmitContext): boolean;
|
||||
|
||||
/**
|
||||
* 按下指定按键
|
||||
* @param key 按键码
|
||||
* @returns 是否至少有一个已实现的指令被因此触发,包括将要延时触发的
|
||||
*/
|
||||
down(key: KeyCode): boolean;
|
||||
|
||||
/**
|
||||
* 松开指定按键
|
||||
* @param key 按键码
|
||||
* @returns 是否至少有一个已实现的指令被因此触发,包括将要延时触发的
|
||||
*/
|
||||
up(key: KeyCode): boolean;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user