Tought event to Keybord event


#1

Hi! Tell me please how to change this code?
I want the man to jump from the keyboard. I tried to change the code myself, but nothing happened.
Here is this code:
cc.eventManager.addListener({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches: true,
onTouchBegan: this.onTouchBegan,
onTouchMoved: this.onTouchMoved,
onTouchEnded: this.onTouchEnded
}, this)
onTouchBegan:function(touch, event) {
var pos = touch.getLocation();
event.getCurrentTarget().recognizer.beginPoint(pos.x, pos.y);
return true;
},

onTouchMoved:function(touch, event) {
    var pos = touch.getLocation();
    event.getCurrentTarget().recognizer.movePoint(pos.x, pos.y);
},

onTouchEnded:function(touch, event) {
    var rtn = event.getCurrentTarget().recognizer.endPoint();
    cc.log("rnt = " + rtn);
    switch (rtn) {
        case "up":
            event.getCurrentTarget().jump();
            break;
        default:
            break;
    }
},

#2

@AlinaKrup,

You can have Keyboard event listener to fetch input from Keyboard.

if (‘keyboard’ in cc.sys.capabilities) {
cc.eventManager.addListener({
event: cc.EventListener.KEYBOARD,
onKeyPressed: function (key, event) {
var strTemp = “Key down:” + key;
},
onKeyReleased: function (key, event) {
var strTemp = “Key up:” + key;
}
}, this);
} else {
cc.log(“KEYBOARD Not supported”);
}

Regards,
Gurudath