piskel/js/service/keyboard/KeycodeTranslator.js
jdescottes 25e6470499 feature : add keyboard shortcuts : keycodes
+ moved keycode translation to KeycodeTranslator
+ made KeycodeTranslator more generic to handle 0-9 and a-z keys
+ small refactor in KeyboardEventService
2013-11-17 21:15:53 +01:00

19 lines
497 B
JavaScript

(function () {
var specialKeys = {};
var ns = $.namespace('service.keyboard');
ns.KeycodeTranslator= {
toChar : function (keycode) {
if (keycode >= 48 && keycode <= 57) {
// key is 0-9
return (keycode - 48) + "";
} else if (keycode >= 65 && keycode <= 90) {
// key is a-z, we'll use base 36 to get the string representation
return (keycode - 65 + 10).toString(36);
} else {
return specialKeys[keycode];
}
}
};
})();