diff --git a/README.md b/README.md index eaa3332..f5b7eae 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ Keypress ======== -Version 2.0.1 +Version 2.0.2 Keypress is a robust keyboard input capturing Javascript utility focused on input for games. For details and documentation, please @@ -13,6 +13,11 @@ released under the Apache License, version 2.0 **What's new** --------------- +2.0.2 + +* Fixed a bug that prevented combos from unregistering, and updated the docs for how to unregister properly. Thanks to [pelly](https://github.com/pelly) and [g00fy-](https://github.com/g00fy-). [Issue # 34](https://github.com/dmauro/Keypress/issues/34). +* Added [AMD](http://requirejs.org/docs/whyamd.html) support. [Issue #37](https://github.com/dmauro/Keypress/issues/37). + 2.0.1 * Fixed a big ole bug with meta/cmd combos. Thanks to [lexey111](https://github.com/lexey111). [Issue #29](https://github.com/dmauro/Keypress/issues/29). diff --git a/bower.json b/bower.json index 82c3085..c438598 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name" : "Keypress", - "version" : "2.0.1", + "version" : "2.0.2", "main" : "keypress.js", "description" : "a robust keyboard input capturing Javascript utility focused on input for games. For details and documentation, please visit http://dmauro.github.io/Keypress/", "devDependencies" : { diff --git a/coffee-compiler.sh b/coffee-compiler.sh index 5bafca4..9e5b939 100755 --- a/coffee-compiler.sh +++ b/coffee-compiler.sh @@ -1,5 +1,5 @@ #!/bin/bash -VERSION="2.0.1" +VERSION="2.0.2" YEAR="2014" cd "$( cd "$( dirname "$0" )" && pwd )" coffee -c keypress.coffee diff --git a/keypress-2.0.1.min.js b/keypress-2.0.1.min.js deleted file mode 100644 index 8dbe905..0000000 --- a/keypress-2.0.1.min.js +++ /dev/null @@ -1,31 +0,0 @@ -/* - Keypress version 2.0.1 (c) 2014 David Mauro. - Licensed under the Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0 -*/ -(function(){var u,w,x,y,p,v,C,D,E,F,q,r,o,k,s,z,G,A={}.hasOwnProperty,i=[].indexOf||function(a){for(var c=0,b=this.length;ci.call(a,"cmd")?!1:!0};f.prototype._prevent_default=function(a,c){if((c||this.should_suppress_event_defaults)&&!this.should_force_event_defaults)if(a.preventDefault?a.preventDefault():a.returnValue=!1,a.stopPropagation)return a.stopPropagation()};f.prototype._get_active_combos=function(a){var c, -b,d=this;c=[];b=v(this._keys_down,function(b){return b!==a});b.push(a);this._match_combo_arrays(b,function(a){if(d._cmd_bug_check(a.keys))return c.push(a)});this._fuzzy_match_combo_arrays(b,function(a){if(!(0<=i.call(c,a))&&!a.is_solitary&&d._cmd_bug_check(a.keys))return c.push(a)});return c};f.prototype._get_potential_combos=function(a){var c,b,d,e,g;b=[];g=this._registered_combos;d=0;for(e=g.length;dl;e=0<=l?++h:--h)if((c=this._active_combos[e])&&c.is_exclusive&&a.is_exclusive){c=c.keys;if(!j){f=0;for(n=c.length;fi.call(a.keys,b)){j=!1;break}}if(g&&!j){m=a.keys;f=0;for(n=m.length;fi.call(c,b)){g=!0;break}}j&&(d?(c=this._active_combos.splice(e, -1)[0],null!=c&&c.reset()):(c=this._active_combos.splice(e,1,a)[0],null!=c&&c.reset(),d=!0),g=!1)}}g&&this._active_combos.unshift(a);return j||g};f.prototype._remove_from_active_combos=function(a){var c,b,d,e;b=d=0;for(e=this._active_combos.length;0<=e?de;b=0<=e?++d:--d)if(c=this._active_combos[b],c===a){a=this._active_combos.splice(b,1)[0];a.reset();break}};f.prototype._get_possible_sequences=function(){var a,c,b,d,e,g,j,h,f,n,l,m;d=[];n=this._registered_combos;g=0;for(f=n.length;g=l;c=1<=l?++j:--j)if(e=this._sequence.slice(-c),a.is_sequence){if(0>i.call(a.keys,"shift")&&(e=v(e,function(a){return"shift"!==a}),!e.length))continue;c=h=0;for(m=e.length;0<=m?hm;c=0<=m?++h:--h)if(a.keys[c]===e[c])b=!0;else{b=!1;break}b&&d.push(a)}}return d};f.prototype._add_key_to_sequence=function(a,c){var b,d,e,g;this._sequence.push(a);d=this._get_possible_sequences();if(d.length){e=0;for(g=d.length;e=m;b=1<=m?++f:--f)if(g=v(this._sequence,function(a){return 0<=i.call(c.keys,"shift")?!0:"shift"!== -a}).slice(-b),c.keys.length===g.length){b=t=0;for(k=g.length;0<=k?tk;b=0<=k?++t:--t)if(e=g[b],!(0>i.call(c.keys,"shift")&&"shift"===e)&&!("shift"===a&&0>i.call(c.keys,"shift")))if(c.keys[b]===e)d=!0;else{d=!1;break}}if(d)return c}return!1};f.prototype._receive_input=function(a,c){var b;if(this._prevent_capture)this._keys_down.length&&(this._keys_down=[]);else if(b=x(a.keyCode),(c||this._keys_down.length||!("alt"===b||b===k))&&b)return c?this._key_down(b,a):this._key_up(b,a)};f.prototype._fire= -function(a,c,b,d){"function"===typeof c["on_"+a]&&this._prevent_default(b,!0!==c["on_"+a].call(c["this"],b,c.count,d));"release"===a&&(c.count=0);if("keyup"===a)return c.keyup_fired=!0};f.prototype._match_combo_arrays=function(a,c){var b,d,e,g;g=this._registered_combos;d=0;for(e=g.length;dg;b=0<=g?++d:--d)this._keys_down[b]===e&&this._keys_down.splice(b,1)}d=this._get_active_combos(a);e=this._get_potential_combos(a);g=0;for(j=d.length;gi.call(this._keys_down,a)&&this._keys_down.push(a)};f.prototype._handle_combo_down=function(a,c,b,d){var e,g,j,f,k;if(0>i.call(a.keys,b))return!1;this._prevent_default(d, -a&&a.prevent_default);e=!1;if(0<=i.call(this._keys_down,b)&&(e=!0,!a.allows_key_repeat()))return!1;j=this._add_to_active_combos(a,b);b=a.keyup_fired=!1;if(a.is_exclusive){f=0;for(k=c.length;fa.keys.length){b=!0;break}}if(!b&&(a.is_counting&&"function"===typeof a.on_keydown&&(a.count+=1),j))return this._fire("keydown",a,d,e)};f.prototype._key_up=function(a,c){var b,d,e,g,f,h;b=a;(e=y(a,c))&&(a=e);e=r[b];c.shiftKey?e&&0<=i.call(this._keys_down,e)||(a=b): -b&&0<=i.call(this._keys_down,b)||(a=e);(g=this._get_sequence(a))&&this._fire("keyup",g,c);if(0>i.call(this._keys_down,a))return!1;g=f=0;for(h=this._keys_down.length;0<=h?fh;g=0<=h?++f:--f)if((d=this._keys_down[g])===a||d===e||d===b){this._keys_down.splice(g,1);break}d=this._active_combos.length;e=[];h=this._active_combos;g=0;for(f=h.length;gd;b=0<=d?++c:--c)if(a===f._registered_combos[b]){f._registered_combos.splice(b,1);break}else e.push(void 0);return e};if(a.keys)return b(a);g=this._registered_combos;d=0;for(e=g.length;de;b=0<=e?++d:--d)if(a[b]!==c[b])return!1;return!0};C=function(a, -c){var b,d,e;d=0;for(e=a.length;di.call(c,b))return!1;return!0};D=function(a,c){var b,d,e,g;e=d=0;for(g=a.length;e=d)d=b;else return!1;return!0};o=function(){if(keypress.debug)return console.log.apply(console,arguments)};E=function(a){var c,b,d;c=!1;for(d in q)if(b=q[d],a===b){c=!0;break}if(!c)for(d in r)if(b=r[d],a===b){c=!0;break}return c};G=function(a){var c,b,d,e,g,f,h;g=!0;a.keys.length||o("You're trying to bind a combo with no keys:",a);b= -f=0;for(h=a.keys.length;0<=h?fh;b=0<=h?++f:--f)d=a.keys[b],(c=F[d])&&(d=a.keys[b]=c),"meta"===d&&a.keys.splice(b,1,k),"cmd"===d&&o('Warning: use the "meta" key rather than "cmd" for Windows compatibility');h=a.keys;c=0;for(f=h.length;c",",":"<", -"'":'"',";":":","[":"{","]":"}","\\":"|","`":"~","=":"+","-":"_",1:"!",2:"@",3:"#",4:"$",5:"%",6:"^",7:"&",8:"*",9:"(","0":")"};q={"0":"\\",8:"backspace",9:"tab",12:"num",13:"enter",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"caps",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",44:"print",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i", -74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"cmd",92:"cmd",93:"cmd",96:"num_0",97:"num_1",98:"num_2",99:"num_3",100:"num_4",101:"num_5",102:"num_6",103:"num_7",104:"num_8",105:"num_9",106:"num_multiply",107:"num_add",108:"num_enter",109:"num_subtract",110:"num_decimal",111:"num_divide",124:"print",144:"num",145:"scroll",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",223:"`",224:"cmd", -225:"alt",57392:"ctrl",63289:"num"};-1!==navigator.userAgent.indexOf("Mac OS X")&&(k="cmd");-1!==navigator.userAgent.indexOf("Opera")&&(q["17"]="cmd")}).call(this); diff --git a/keypress-2.0.2.min.js b/keypress-2.0.2.min.js new file mode 100644 index 0000000..869dbc9 --- /dev/null +++ b/keypress-2.0.2.min.js @@ -0,0 +1,31 @@ +/* + Keypress version 2.0.2 (c) 2014 David Mauro. + Licensed under the Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0 +*/ +(function(){var p,v,x,y,z,q,w,D,E,F,G,r,s,o,k,t,A,H,B={}.hasOwnProperty,i=[].indexOf||function(a){for(var c=0,b=this.length;ci.call(a,"cmd")?!1:!0};g.prototype._prevent_default=function(a,c){if((c||this.should_suppress_event_defaults)&&!this.should_force_event_defaults)if(a.preventDefault?a.preventDefault():a.returnValue=!1,a.stopPropagation)return a.stopPropagation()};g.prototype._get_active_combos= +function(a){var c,b;c=[];b=w(this._keys_down,function(b){return b!==a});b.push(a);this._match_combo_arrays(b,function(a){return function(b){if(a._cmd_bug_check(b.keys))return c.push(b)}}(this));this._fuzzy_match_combo_arrays(b,function(a){return function(b){if(!(0<=i.call(c,b))&&!b.is_solitary&&a._cmd_bug_check(b.keys))return c.push(b)}}(this));return c};g.prototype._get_potential_combos=function(a){var c,b,d,e,f;b=[];f=this._registered_combos;d=0;for(e=f.length;dl;e=0<=l?++j:--j)if((c=this._active_combos[e])&&c.is_exclusive&&a.is_exclusive){c=c.keys;if(!h){g=0;for(n=c.length;gi.call(a.keys,b)){h=!1;break}}if(f&&!h){m=a.keys;g=0;for(n=m.length;gi.call(c, +b)){f=!0;break}}h&&(d?(c=this._active_combos.splice(e,1)[0],null!=c&&c.reset()):(c=this._active_combos.splice(e,1,a)[0],null!=c&&c.reset(),d=!0),f=!1)}}f&&this._active_combos.unshift(a);return h||f};g.prototype._remove_from_active_combos=function(a){var c,b,d,e;b=d=0;for(e=this._active_combos.length;0<=e?de;b=0<=e?++d:--d)if(c=this._active_combos[b],c===a){a=this._active_combos.splice(b,1)[0];a.reset();break}};g.prototype._get_possible_sequences=function(){var a,c,b,d,e,f,h,j,g,n,l,m;d=[];n= +this._registered_combos;f=0;for(g=n.length;f=l;c=1<=l?++h:--h)if(e=this._sequence.slice(-c),a.is_sequence){if(0>i.call(a.keys,"shift")&&(e=w(e,function(a){return"shift"!==a}),!e.length))continue;c=j=0;for(m=e.length;0<=m?jm;c=0<=m?++j:--j)if(a.keys[c]===e[c])b=!0;else{b=!1;break}b&&d.push(a)}}return d};g.prototype._add_key_to_sequence=function(a,c){var b,d,e,f;this._sequence.push(a);d=this._get_possible_sequences();if(d.length){e=0; +for(f=d.length;e=m;b=1<=m?++g:--g)if(f=w(this._sequence,function(a){return 0<= +i.call(c.keys,"shift")?!0:"shift"!==a}).slice(-b),c.keys.length===f.length){b=u=0;for(k=f.length;0<=k?uk;b=0<=k?++u:--u)if(e=f[b],!(0>i.call(c.keys,"shift")&&"shift"===e)&&!("shift"===a&&0>i.call(c.keys,"shift")))if(c.keys[b]===e)d=!0;else{d=!1;break}}if(d)return c}return!1};g.prototype._receive_input=function(a,c){var b;if(this._prevent_capture)this._keys_down.length&&(this._keys_down=[]);else if(b=y(a.keyCode),(c||this._keys_down.length||!("alt"===b||b===k))&&b)return c?this._key_down(b,a): +this._key_up(b,a)};g.prototype._fire=function(a,c,b,d){"function"===typeof c["on_"+a]&&this._prevent_default(b,!0!==c["on_"+a].call(c["this"],b,c.count,d));"release"===a&&(c.count=0);if("keyup"===a)return c.keyup_fired=!0};g.prototype._match_combo_arrays=function(a,c){var b,d,e,f;f=this._registered_combos;d=0;for(e=f.length;df;b=0<=f?++d:--d)this._keys_down[b]===e&&this._keys_down.splice(b,1)}d=this._get_active_combos(a);e=this._get_potential_combos(a);f=0;for(h=d.length;fi.call(this._keys_down,a)&&this._keys_down.push(a)};g.prototype._handle_combo_down=function(a,c,b, +d){var e,f,h,g,k;if(0>i.call(a.keys,b))return!1;this._prevent_default(d,a&&a.prevent_default);e=!1;if(0<=i.call(this._keys_down,b)&&(e=!0,!a.allows_key_repeat()))return!1;h=this._add_to_active_combos(a,b);b=a.keyup_fired=!1;if(a.is_exclusive){g=0;for(k=c.length;ga.keys.length){b=!0;break}}if(!b&&(a.is_counting&&"function"===typeof a.on_keydown&&(a.count+=1),h))return this._fire("keydown",a,d,e)};g.prototype._key_up=function(a,c){var b,d,e,f,h,g;b=a;(e= +z(a,c))&&(a=e);e=s[b];c.shiftKey?e&&0<=i.call(this._keys_down,e)||(a=b):b&&0<=i.call(this._keys_down,b)||(a=e);(f=this._get_sequence(a))&&this._fire("keyup",f,c);if(0>i.call(this._keys_down,a))return!1;f=h=0;for(g=this._keys_down.length;0<=g?hg;f=0<=g?++h:--h)if((d=this._keys_down[f])===a||d===e||d===b){this._keys_down.splice(f,1);break}d=this._active_combos.length;e=[];g=this._active_combos;f=0;for(h=g.length;fd;b=0<=d?++c:--c)if(a===g._registered_combos[b]){g._registered_combos.splice(b,1);break}else e.push(void 0);return e}; +if(a.keys)return b(a);f=this._registered_combos;d=0;for(e=f.length;de;b=0<=e?++d:--d)if(a[b]!==c[b])return!1;return!0};D=function(a,c){var b,d,e;d=0;for(e=a.length;di.call(c,b))return!1;return!0};E=function(a,c){var b,d,e,f;e=d=0;for(f=a.length;e=d)d=b;else return!1;return!0};o=function(){if(p.debug)return console.log.apply(console,arguments)};F=function(a){var c,b,d;c=!1;for(d in r)if(b=r[d],a===b){c=!0;break}if(!c)for(d in s)if(b=s[d],a===b){c=!0;break}return c};H=function(a){var c,b,d,e,f,g,j;f=!0;a.keys.length|| +o("You're trying to bind a combo with no keys:",a);b=g=0;for(j=a.keys.length;0<=j?gj;b=0<=j?++g:--g)d=a.keys[b],(c=G[d])&&(d=a.keys[b]=c),"meta"===d&&a.keys.splice(b,1,k),"cmd"===d&&o('Warning: use the "meta" key rather than "cmd" for Windows compatibility');j=a.keys;c=0;for(g=j.length;c",",":"<","'":'"',";":":","[":"{","]":"}","\\":"|","`":"~","=":"+","-":"_",1:"!",2:"@",3:"#",4:"$",5:"%",6:"^",7:"&",8:"*",9:"(","0":")"};r={"0":"\\",8:"backspace",9:"tab",12:"num",13:"enter",16:"shift",17:"ctrl",18:"alt",19:"pause",20:"caps",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",44:"print",45:"insert",46:"delete",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9", +65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",91:"cmd",92:"cmd",93:"cmd",96:"num_0",97:"num_1",98:"num_2",99:"num_3",100:"num_4",101:"num_5",102:"num_6",103:"num_7",104:"num_8",105:"num_9",106:"num_multiply",107:"num_add",108:"num_enter",109:"num_subtract",110:"num_decimal",111:"num_divide",124:"print",144:"num",145:"scroll",186:";",187:"=",188:",",189:"-",190:".", +191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",223:"`",224:"cmd",225:"alt",57392:"ctrl",63289:"num"};-1!==navigator.userAgent.indexOf("Mac OS X")&&(k="cmd");-1!==navigator.userAgent.indexOf("Opera")&&(r["17"]="cmd");"function"===typeof define&&define.amd?define([],function(){return p}):window.keypress=p}).call(this); diff --git a/keypress.js b/keypress.js index 8d2c859..86e01cb 100644 --- a/keypress.js +++ b/keypress.js @@ -1,4 +1,5 @@ -// Generated by CoffeeScript 1.6.3 +// Generated by CoffeeScript 1.7.1 + /* Copyright 2014 David Mauro @@ -18,7 +19,7 @@ Keypress is a robust keyboard input capturing Javascript utility focused on input for games. version 2.0.1 -*/ + */ /* @@ -36,11 +37,10 @@ Combo options available and their defaults: on_keyup : null - A function that is called when the combo is released. on_release : null - A function that is called when all keys in the combo are released. this : undefined - Defines the scope for your callback functions. -*/ - + */ (function() { - var Combo, _change_keycodes_by_browser, _compare_arrays, _compare_arrays_sorted, _convert_key_to_readable, _convert_to_shifted_key, _decide_meta_key, _factory_defaults, _filter_array, _is_array_in_array, _is_array_in_array_sorted, _key_is_valid, _keycode_alternate_names, _keycode_dictionary, _keycode_shifted_keys, _log_error, _metakey, _modifier_event_mapping, _modifier_keys, _validate_combo, + var Combo, keypress, _change_keycodes_by_browser, _compare_arrays, _compare_arrays_sorted, _convert_key_to_readable, _convert_to_shifted_key, _decide_meta_key, _factory_defaults, _filter_array, _is_array_in_array, _is_array_in_array_sorted, _key_is_valid, _keycode_alternate_names, _keycode_dictionary, _keycode_shifted_keys, _log_error, _metakey, _modifier_event_mapping, _modifier_keys, _validate_combo, __hasProp = {}.hasOwnProperty, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; @@ -57,7 +57,7 @@ Combo options available and their defaults: _metakey = "ctrl"; - window.keypress = {}; + keypress = {}; keypress.debug = false; @@ -90,8 +90,7 @@ Combo options available and their defaults: keypress.Listener = (function() { function Listener(element, defaults) { - var attach_handler, property, value, - _this = this; + var attach_handler, property, value; this.should_suppress_event_defaults = false; this.should_force_event_defaults = false; this.sequence_delay = 800; @@ -115,24 +114,30 @@ Combo options available and their defaults: return target.attachEvent("on" + event, handler); } }; - attach_handler(element, "keydown", function(e) { - e = e || window.event; - _this._receive_input(e, true); - return _this._bug_catcher(e); - }); - attach_handler(element, "keyup", function(e) { - e = e || window.event; - return _this._receive_input(e, false); - }); - attach_handler(window, "blur", function() { - var key, _i, _len, _ref; - _ref = _this._keys_down; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - key = _ref[_i]; - _this._key_up(key, {}); - } - return _this._keys_down = []; - }); + attach_handler(element, "keydown", (function(_this) { + return function(e) { + e = e || window.event; + _this._receive_input(e, true); + return _this._bug_catcher(e); + }; + })(this)); + attach_handler(element, "keyup", (function(_this) { + return function(e) { + e = e || window.event; + return _this._receive_input(e, false); + }; + })(this)); + attach_handler(window, "blur", (function(_this) { + return function() { + var key, _i, _len, _ref; + _ref = _this._keys_down; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + key = _ref[_i]; + _this._key_up(key, {}); + } + return _this._keys_down = []; + }; + })(this)); } Listener.prototype._bug_catcher = function(e) { @@ -163,26 +168,29 @@ Combo options available and their defaults: }; Listener.prototype._get_active_combos = function(key) { - var active_combos, keys_down, - _this = this; + var active_combos, keys_down; active_combos = []; keys_down = _filter_array(this._keys_down, function(down_key) { return down_key !== key; }); keys_down.push(key); - this._match_combo_arrays(keys_down, function(match) { - if (_this._cmd_bug_check(match.keys)) { - return active_combos.push(match); - } - }); - this._fuzzy_match_combo_arrays(keys_down, function(match) { - if (__indexOf.call(active_combos, match) >= 0) { - return; - } - if (!(match.is_solitary || !_this._cmd_bug_check(match.keys))) { - return active_combos.push(match); - } - }); + this._match_combo_arrays(keys_down, (function(_this) { + return function(match) { + if (_this._cmd_bug_check(match.keys)) { + return active_combos.push(match); + } + }; + })(this)); + this._fuzzy_match_combo_arrays(keys_down, (function(_this) { + return function(match) { + if (__indexOf.call(active_combos, match) >= 0) { + return; + } + if (!(match.is_solitary || !_this._cmd_bug_check(match.keys))) { + return active_combos.push(match); + } + }; + })(this)); return active_combos; }; @@ -349,8 +357,10 @@ Combo options available and their defaults: } for (i = _k = 0, _ref2 = sequence.length; 0 <= _ref2 ? _k < _ref2 : _k > _ref2; i = 0 <= _ref2 ? ++_k : --_k) { seq_key = sequence[i]; - if (__indexOf.call(combo.keys, "shift") < 0 ? seq_key === "shift" : void 0) { - continue; + if (__indexOf.call(combo.keys, "shift") < 0) { + if (seq_key === "shift") { + continue; + } } if (key === "shift" && __indexOf.call(combo.keys, "shift") < 0) { continue; @@ -645,7 +655,7 @@ Combo options available and their defaults: combo = new Combo(combo_dictionary); if (_validate_combo(combo)) { this._registered_combos.push(combo); - return true; + return combo; } }; @@ -660,24 +670,25 @@ Combo options available and their defaults: }; Listener.prototype.unregister_combo = function(keys_or_combo) { - var combo, unregister_combo, _i, _len, _ref, - _this = this; + var combo, unregister_combo, _i, _len, _ref; if (!keys_or_combo) { return false; } - unregister_combo = function(combo) { - var i, _i, _ref, _results; - _results = []; - for (i = _i = 0, _ref = _this._registered_combos.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { - if (combo === _this._registered_combos[i]) { - _this._registered_combos.splice(i, 1); - break; - } else { - _results.push(void 0); + unregister_combo = (function(_this) { + return function(combo) { + var i, _i, _ref, _results; + _results = []; + for (i = _i = 0, _ref = _this._registered_combos.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) { + if (combo === _this._registered_combos[i]) { + _this._registered_combos.splice(i, 1); + break; + } else { + _results.push(void 0); + } } - } - return _results; - }; + return _results; + }; + })(this); if (keys_or_combo.keys) { return unregister_combo(keys_or_combo); } else { @@ -1060,4 +1071,12 @@ Combo options available and their defaults: _change_keycodes_by_browser(); + if (typeof define === "function" && define.amd) { + define([], function() { + return keypress; + }); + } else { + window.keypress = keypress; + } + }).call(this);