* takes the event and returns the key character * * @param {Event} e * @return {string}
(e)
| 228 | * @return {string} |
| 229 | */ |
| 230 | function _characterFromEvent(e) { |
| 231 | |
| 232 | // for keypress events we should return the character as is |
| 233 | if (e.type == 'keypress') { |
| 234 | var character = String.fromCharCode(e.which); |
| 235 | |
| 236 | // if the shift key is not pressed then it is safe to assume |
| 237 | // that we want the character to be lowercase. this means if |
| 238 | // you accidentally have caps lock on then your key bindings |
| 239 | // will continue to work |
| 240 | // |
| 241 | // the only side effect that might not be desired is if you |
| 242 | // bind something like 'A' cause you want to trigger an |
| 243 | // event when capital A is pressed caps lock will no longer |
| 244 | // trigger the event. shift+a will though. |
| 245 | if (!e.shiftKey) { |
| 246 | character = character.toLowerCase(); |
| 247 | } |
| 248 | |
| 249 | return character; |
| 250 | } |
| 251 | |
| 252 | // for non keypress events the special maps are needed |
| 253 | if (_MAP[e.which]) { |
| 254 | return _MAP[e.which]; |
| 255 | } |
| 256 | |
| 257 | if (_KEYCODE_MAP[e.which]) { |
| 258 | return _KEYCODE_MAP[e.which]; |
| 259 | } |
| 260 | |
| 261 | // if it is not in the special map |
| 262 | |
| 263 | // with keydown and keyup events the character seems to always |
| 264 | // come in as an uppercase character whether you are pressing shift |
| 265 | // or not. we should make sure it is always lowercase for comparisons |
| 266 | return String.fromCharCode(e.which).toLowerCase(); |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * checks if two arrays are equal |
no outgoing calls
no test coverage detected