Class: Keyboard
键盘抽象
示例:
// 所有快捷键只有当前画布的canvas成为页面焦点时才有效
// 绑定快捷键
let keyboard = stage.keyboard;
keyboard.bindKey('Shift+a', ()=> {
console.log('shift+a');
});
// 解绑
keyboard.unbind('Shift+a');
Hierarchy
↳
Keyboard
Table of contents
Constructors
Properties
Methods
- addEventListener
- bindKey
- disable
- dispatchEvent
- enable
- fireKey
- getKeyBinding
- hasListener
- init
- isAltDown
- isControlDown
- isKeyRegistered
- isKeydown
- isMetaDown
- isMouseOnInputDomElement
- isShiftDown
- keydownHandler
- keyupHandler
- on
- removeEventListener
- sendKey
- unBind
- unbind
Constructors
constructor
new Keyboard(stage
)
Parameters
Name | Type |
---|---|
stage | Stage |
Overrides
Properties
_disabled
_disabled: boolean
= false
是否禁用
debug
debug: boolean
= false
调试开关,如果设置为true,会在控制台输出按键信息
keyMap
keyMap: Map
<string
, boolean
>
preKeydownEvent
preKeydownEvent: any
regMap
regMap: Map
<string
, Function
>
stage
stage: Stage
Methods
addEventListener
addEventListener(type
, callback
): void
增加事件监听
Parameters
Name | Type | Description |
---|---|---|
type | string | 事件类型 |
callback | Function |
Returns
void
Inherited from
bindKey
bindKey(keyInfo
, fn
): void
绑定按键
Parameters
Name | Type | Description |
---|---|---|
keyInfo | string | 例如"Control+a" 、"Meta+a"、 ”G" 、”Shift+1“ |
fn | Function | - |
Returns
void
disable
disable(): void
禁用jtopo的快捷键
Returns
void
dispatchEvent
dispatchEvent(event
): void
分发事件
Parameters
Name | Type |
---|---|
event | any |
Returns
void
Inherited from
enable
enable(): void
启用jtopo默认的快捷键
Returns
void
fireKey
fireKey(keyArray
, event
, isMouseOn
): void
Parameters
Name | Type |
---|---|
keyArray | any |
event | any |
isMouseOn | any |
Returns
void
getKeyBinding
getKeyBinding(keyInfo
): Function
获取按键绑定的函数
Parameters
Name | Type |
---|---|
keyInfo | string |
Returns
Function
hasListener
hasListener(type
): boolean
是否有该类型的监听
Parameters
Name | Type |
---|---|
type | string |
Returns
boolean
Inherited from
init
init(): void
Returns
void
isAltDown
isAltDown(): boolean
Returns
boolean
isControlDown
isControlDown(): boolean
Returns
boolean
isKeyRegistered
isKeyRegistered(keyInfo
): boolean
判断按键是否已经注册
Parameters
Name | Type |
---|---|
keyInfo | string |
Returns
boolean
isKeydown
isKeydown(keyInfo
): boolean
指定的单个键是否按下
Parameters
Name | Type |
---|---|
keyInfo | string |
Returns
boolean
isMetaDown
isMetaDown(): boolean
Returns
boolean
isMouseOnInputDomElement
isMouseOnInputDomElement(): boolean
Returns
boolean
isShiftDown
isShiftDown(): boolean
Returns
boolean
keydownHandler
keydownHandler(event
): void
Parameters
Name | Type |
---|---|
event | KeyboardEvent |
Returns
void
keyupHandler
keyupHandler(event
): void
Parameters
Name | Type |
---|---|
event | KeyboardEvent |
Returns
void
on
on(type
, callback
): void
增加监听事件, 功能完全等同于addEventListener,一种简写
Parameters
Name | Type | Description |
---|---|---|
type | string | 事件类型 |
callback | Function | 事件处理函数 |
Returns
void
Inherited from
removeEventListener
removeEventListener(type
, callback
): any
移除一个事件监听
Parameters
Name | Type |
---|---|
type | string |
callback | Function |
Returns
any
Inherited from
EventTarget.removeEventListener
sendKey
sendKey(keyStr
, event
): void
Parameters
Name | Type |
---|---|
keyStr | string |
event | any |
Returns
void
unBind
unBind(keyInfo
): void
解绑按键 , 请使用小写的 unbind 代替 unBind
Deprecated
Parameters
Name | Type |
---|---|
keyInfo | string |
Returns
void
unbind
unbind(keyInfo
): void
解绑按键
Parameters
Name | Type | Description |
---|---|---|
keyInfo | string | 例如"Control+a" 、"Meta+a"、 ”G" 、”Shift+1“ |
Returns
void