cocos2dx_lua键盘监听

2023-01-01 15:23:19 浏览数 (2)

开发环境: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)
lua

0 人点赞