The Events class is a collection of functions for handling events across browsers. Here is the documentation for Event.js.
Whenever you add an event to a DOM element (not to be confused with the //Events// class in Class.Extras) the argument passed to that function will be the event native. This has been extended like other natives to have additional properties by MooTools.
$('eventExample').addEvent('keydown', function(event){ console.log(event.key); /*returns the lowercase letter pressed*/ console.log(event.shift); /*returns true if the key pressed is shift*/ if (event.key == 's' && event.control) console.log('document saved'); });
Event.stop will stop an Event from propigating and will also execute .preventDefault
Event.preventDefault will prevent the default action of the event from completing (for example, clicking a url and executing .preventDefault will still execute the onclick event(s) attached to the link, but will NOT follow the link).
Event.stopPropagation will execute the default behavior and any events (such as onclick) attached to the element but will not allow the event to bubble up through the DOM (so that if there is an event attached to document.body.onclick and the user clicks a link, the link's events will fire, but the event on the document.body will not).
MooTools defines a handful of key codes but you can add more definitions for special uses. This allows you to add event handlers for those keys:
Event.Keys.whatever = 80; $(myelement).addEvent(keydown, function(event){ if (event.key == 'whatever') console.log(whatever key clicked). });
By default, MooTools defines the following keys: