演示样例代码例如以下所看到的:
local listenerKey= cc.EventListenerKeyboard:create() local function onKeyReleaseed(keycode,event) print("keycode:"..keycode) if keycode == cc.KeyCode.KEY_BACKSPACE then cc.Director:getInstance():endToLua() end end listenerKey:registerScriptHandler(onKeyReleaseed,cc.Handler.EVENT_KEYBOARD_RELEASED) layer:getEventDispatcher():addEventListenerWithSceneGraphPriority(listenerKey, layer)
主要须要注意的是必须把回调函数绑定在cc.Handler.EVENT_KEYBOARD_RELEASED上。绑定在cc.Handler.EVENT_KEYBOARD_PRESSED上回调函数不会被运行,Android上的按键就是如此,眼下也不知道是什么原因