按键事件

注意

仅在Page中使用生效

基础用法

setup中编写 onKeyDownonKeyUp 方法,并在return中返回此方法。


function onKeyDown(keyEvent: ESKeyEvent) {
  //按键被按下
  //处理业务逻辑
}

function onKeyUp(keyEvent: ESKeyEvent) {
  //按键被抬起
  //处理业务逻辑
}

return {
  onKeyDown,
  onKeyUp,
}

API

DataStructure

ESKeyEvent

按键事件

NameDescriptionTypeDefault
action按键动作ESKeyAction-
keyCode键值ESKeyCode-
keyRepeat重复按键的次数number-

ESKeyAction

按键动作

NameDescriptionTypeDefault
ES_KEY_ACTION_DOWN按下ESKeyAction-
ES_KEY_ACTION_UP抬起ESKeyAction-

ESKeyCode

按键值

NameDescriptionTypeDefault
ES_KEYCODE_ENTER回车键number66
ES_KEYCODE_DPAD_CENTER导航键 确定键number23
ES_KEYCODE_DPAD_UP导航键 向上number19
ES_KEYCODE_DPAD_DOWN导航键 向下number20
ES_KEYCODE_DPAD_LEFT导航键 向左number21
ES_KEYCODE_DPAD_RIGHT导航键 向右number22
ES_KEYCODE_BACK返回键number4
ES_KEYCODE_ESCAPE回退键number111
ES_KEYCODE_MENU菜单键number82
ES_KEYCODE_SEARCH搜索键number84

Exposes

NameDescriptionType
onKeyDown监听按键按下Function
onKeyUp监听按键抬起Function