开发环境:cocos2dx 3.17 开发语言:lua 这里用lua实现对键盘的监听 下面直接上代码吧
代码语言:javascript复制local function keyboardPressed(KeyCode,event)
print(KeyCode)
end
local function keyboardReleased(KeyCode,event)
end
local listener = cc.EventListenerKeyboard:create()
listener:registerScriptHandler(keyboardPressed, cc.Handler.EVENT_KEYBOARD_PRESSED)
listener:registerScriptHandler(keyboardReleased, cc.Handler.EVENT_KEYBOARD_RELEASED)
local eventDispatcher = self:getEventDispatcher()
eventDispatcher:addEventListenerWithSceneGraphPriority(listener,self)