Interface: keys

MC.keys


The MC.keys object contains all key related variables.
Upon initialisation it sets up document event listeners for keyup & keydown events
Each supported key has a MC.keys.# member object where the # is the key name
Within this are:

(1) down {Boolean} true if the key is currently depressed, else false
(2) onDown {function} A placeholder function for Developer customisation, called when the key is depressed
(3) onUp {function} A placeholder function for Developer customisation, called when the key is released

The following keys are supported by the MaxCanvas engine:
N.B. these names are to be used exactly as typed here
Misc: back, tab, enter, shift, ctrl, caps, esc, space, pageUp, pageDown, end, home, leftArrow, upArrow, rightArrow, downArrow, del (N.B. if a choice between left and right, the left is supported. e.g. the left shift key is supported, the right is not)
Numbers: _0,_1,_2,_3,_4,_5,_6,_7,_8,_9 (N.B. There are prefixed with an underscore to comply with JS naming rules)
Letters: a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
NumberPad: num0,num1,num2,num3,num4,num5,num6,num7,num8,num9
Other keys are not supported as they may vary based upon international keyboard layouts or have possible browser pre-sets (e.g. F5 is refresh)
Source:

Example

MC.keys.p.onDown = function () {
      myPrintFunction();
};

MC.keys.space.onUp = function () {
      if (gun.status == "ready") {
          gun.fire();
      }
};

MC.keys.m.onDown = function () {
      if (MC.keys.ctrl.down) {
          console.log("MaxCanvas is great!!");
      }
};

Methods

(static) init()


Init initialises the MC.key object, by setting up the keyboard event handlers and pointing them at the different key property objects
Called automatically during the MC.init() call. There should be no need for a Developer to use it.
Source: