开发者

Where does Event.Keys gone?

Did I miss something or the Event.Keys object has gone from mootools since 1.4.0 ?

I cannot get the real value of a key or compare it to the current pressed key :

var modifiers = {
    previous: Event.Keys.left,
    next: Event.Keys.right
};
switch (evt.code){
    case Event.Keys.backspace:
开发者_JAVA技巧        // Do some stuff;
        break;
    case Event.Keys.delete:
        // Do some other stuff
        break;
}

Is ther a possibility this object has move to another object or property ?


erm. Under the new API changes, Event is now known as DOMEvent, a MooTools Type, not a Class. Additionally, event definitions are now private behind a closure in a keys array.

https://github.com/mootools/mootools-core/blob/master/Source/Types/DOMEvent.js

There is an API to work with it:

DOMEvent.defineKeys({
    38: "up"
});

which, regretfully - is one way: You have no getter for the Event.Keys, you cannot set it w/o going through the API either.

You can redefine them as per the source or store a local var of what they mean. You can also refactor it to puncture it.

You can also do pseudo events, like keydown:left

DOMEvent.definePseudo('left', function(split, fn, args){
    // args[0] is the Event instance
    if(args[0].key == 'left') fn.apply(this, args);
});


document.getElement("textarea").addEvent("keydown:left", function(e) {
    alert("left pressed!");
});

the alert above will only fire if you press the left arrow inside your textarea. Hope this helps...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜