diff --git a/keymaster.js b/keymaster.js index 8f5b5fc..37dfb88 100644 --- a/keymaster.js +++ b/keymaster.js @@ -176,9 +176,9 @@ if (keys.length > 1) { mods = getMods(keys); + key = keys[keys.length - 1]; } - key = keys[keys.length - 1]; key = code(key); if (scope === undefined) { @@ -263,12 +263,15 @@ object.attachEvent('on'+event, function(){ method(window.event) }); }; - // set the handlers globally on document - addEvent(document, 'keydown', function(event) { dispatch(event) }); // Passing _scope to a callback to ensure it remains the same by execution. Fixes #48 - addEvent(document, 'keyup', clearModifier); - // reset modifiers to false whenever the window is (re)focused. - addEvent(window, 'focus', resetModifiers); + if(typeof document !== 'undefined'){ + // set the handlers globally on document + addEvent(document, 'keydown', function(event) { dispatch(event) }); // Passing _scope to a callback to ensure it remains the same by execution. Fixes #48 + addEvent(document, 'keyup', clearModifier); + + // reset modifiers to false whenever the window is (re)focused. + addEvent(window, 'focus', resetModifiers); + } // store previously defined key var previousKey = global.key;