82 lines
2.9 KiB
TypeScript
82 lines
2.9 KiB
TypeScript
import { IGraphicApp } from '../app/JlGraphicApp';
|
|
export declare class GlobalKeyboardHelper {
|
|
appKeyboardPluginMap: JlGraphicAppKeyboardPlugin[];
|
|
constructor();
|
|
registerGAKPlugin(plugin: JlGraphicAppKeyboardPlugin): void;
|
|
removeGAKPlugin(plugin: JlGraphicAppKeyboardPlugin): void;
|
|
}
|
|
export declare class JlGraphicAppKeyboardPlugin {
|
|
app: IGraphicApp;
|
|
/**
|
|
* 结构为Map<key.code|key.key|key.keyCode, Map<KeyListener.identifier, KeyListener>>
|
|
*/
|
|
keyListenerMap: Map<number | string, Map<string, KeyListener>>;
|
|
keyListenerStackMap: Map<string, KeyListener[]>;
|
|
constructor(app: IGraphicApp);
|
|
private getOrInit;
|
|
private getOrInitStack;
|
|
/**
|
|
* 注册按键监听,若有旧的,旧的入栈
|
|
* @param keyListener
|
|
*/
|
|
addKeyListener(keyListener: KeyListener): void;
|
|
/**
|
|
* 移除按键监听,若是当前注册的监听,尝试从栈中取出作为按键监听器,若是旧的,则同时移除栈中的监听
|
|
* @param keyListener
|
|
*/
|
|
removeKeyListener(keyListener: KeyListener): void;
|
|
getKeyListenerBy(key: string | number): Map<string, KeyListener> | undefined;
|
|
getKeyListener(e: KeyboardEvent): Map<string, KeyListener> | undefined;
|
|
isKeyListened(key: string | number): boolean;
|
|
/**
|
|
* 获取所有注册监听的键值(组合键)
|
|
*/
|
|
getAllListenedKeys(): string[];
|
|
}
|
|
type KeyboardKeyHandler = (e: KeyboardEvent, app: IGraphicApp) => void;
|
|
export declare enum CombinationKey {
|
|
Ctrl = "Ctrl",
|
|
Alt = "Alt",
|
|
Shift = "Shift"
|
|
}
|
|
export interface KeyListenerOptions {
|
|
value: string | number;
|
|
combinations?: CombinationKey[];
|
|
global?: boolean;
|
|
onPress?: KeyboardKeyHandler;
|
|
pressTriggerAsOriginalEvent?: boolean;
|
|
onRelease?: KeyboardKeyHandler;
|
|
}
|
|
export interface ICompleteKeyListenerOptions {
|
|
value: string | number;
|
|
combinations: CombinationKey[];
|
|
global: boolean;
|
|
onPress?: KeyboardKeyHandler;
|
|
pressTriggerAsOriginalEvent: boolean;
|
|
onRelease?: KeyboardKeyHandler;
|
|
}
|
|
export declare class KeyListener {
|
|
readonly options: ICompleteKeyListenerOptions;
|
|
private isPress;
|
|
constructor(options: KeyListenerOptions);
|
|
static create(options: KeyListenerOptions): KeyListener;
|
|
get value(): string | number;
|
|
get combinations(): string[];
|
|
get identifier(): string;
|
|
get global(): boolean | undefined;
|
|
get onPress(): KeyboardKeyHandler | undefined;
|
|
set onPress(v: KeyboardKeyHandler | undefined);
|
|
get onRelease(): KeyboardKeyHandler | undefined;
|
|
set onRelease(v: KeyboardKeyHandler | undefined);
|
|
get pressTriggerEveryTime(): boolean;
|
|
set pressTriggerEveryTime(v: boolean);
|
|
press(e: KeyboardEvent, app: IGraphicApp): void;
|
|
/**
|
|
* 检查组合键是否匹配
|
|
*/
|
|
checkCombinations(e: KeyboardEvent): boolean;
|
|
release(e: KeyboardEvent, app: IGraphicApp): void;
|
|
onRemove(): void;
|
|
}
|
|
export {};
|