From a29299d8befb7a184d54a2cc742f4fa63f7a196e Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 9 Mar 2013 15:25:42 +0400 Subject: [PATCH] updated keyboard handler with the rest of the key names (number row and punctuation)... Signed-off-by: Alex A. Naanou --- TODO.otl | 2 +- index.html | 12 ++++-------- lib/keyboard.js | 38 ++++++++++++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/TODO.otl b/TODO.otl index ea58b0f..9a39cd5 100755 --- a/TODO.otl +++ b/TODO.otl @@ -6,7 +6,7 @@ [_] load/save state (migrate) [_] load/save from JSON (migrate) [_] basic instructions/docs... - [_] page settngs in full view editor + [_] page settings in full view editor | could even be fixed... [_] 37% Version 1.0 checklist (migration to layout.html) [X] page scaling for full page view diff --git a/index.html b/index.html index 28c61f9..edff405 100755 --- a/index.html +++ b/index.html @@ -157,8 +157,7 @@ var keyboard_config = { title: 'Editor mode.', doc: '', - // 0 - 48: function(){ + '0': function(){ var n = getPageNumber() if(togglePageView('?') == 'on'){ setMagazineScale(getPageTargetScale(1)) @@ -167,25 +166,22 @@ var keyboard_config = { } setCurrentPage(n) }, - Esc: 48, + Esc: '0', - // + - 187: function(){ + '=': function(){ var n = getPageNumber() setMagazineScale(Math.min( getMagazineScale() * 1.2, getPageTargetScale(1))) setCurrentPage(n) }, - // - - 189: function(){ + '-': function(){ var n = getPageNumber() setMagazineScale(Math.max( getMagazineScale() * 0.8, getPageTargetScale(PAGES_IN_RIBBON*2))) setCurrentPage(n) }, - }, // ignore all keys except Esc here... diff --git a/lib/keyboard.js b/lib/keyboard.js index 66b52a6..b35c39f 100755 --- a/lib/keyboard.js +++ b/lib/keyboard.js @@ -10,8 +10,18 @@ /*********************************************************************/ +// Neither _SPECIAL_KEYS nor _KEY_CODES are meant for direct access, use +// toKeyName() and toKeyCode() for a more uniform access. +// +// NOTE: these are un-shifted ASCII key names rather than actual key +// code values. +// NOTE: ASCII letters (capital) are not present because they actually +// match their key codes and are accessible via: +// String.fromCharCode() or .charCodeAt(0) +// NOTE: the lower case letters are accessible by adding 32 to the +// capital key code. // NOTE: don't understand why am I the one who has to write this... -var SPECIAL_KEYS = { +var _SPECIAL_KEYS = { // Special Keys... 9: 'Tab', 33: 'PgUp', 45: 'Ins', 13: 'Enter', 34: 'PgDown', 46: 'Del', @@ -27,18 +37,30 @@ var SPECIAL_KEYS = { 113: 'F2', 117: 'F6', 121: 'F10', 114: 'F3', 118: 'F7', 122: 'F11', 115: 'F4', 119: 'F8', 123: 'F12', + + // number row.. + 49: '1', 50: '2', 51: '3', 52: '4', 53: '5', + 54: '6', 55: '7', 56: '8', 57: '9', 48: '0', + + // punctuation... + // top row... + 192: '`', 189: '-', 187: '=', + // right side of keyboard... + 219: '[', 221: ']', 220: '\\', + 186: ';', 222: '\'', + 188: ',', 190: '.', 191: '/', } -var KEY_CODES = {} -for(var k in SPECIAL_KEYS){ - KEY_CODES[SPECIAL_KEYS[k]] = k +var _KEY_CODES = {} +for(var k in _SPECIAL_KEYS){ + _KEY_CODES[_SPECIAL_KEYS[k]] = k } // XXX some keys look really wrong... function toKeyName(code){ // check for special keys... - var k = SPECIAL_KEYS[code] + var k = _SPECIAL_KEYS[code] if(k != null){ return k } @@ -52,8 +74,8 @@ function toKeyName(code){ } function toKeyCode(c){ - if(c in KEY_CODES){ - return KEY_CODES[c] + if(c in _KEY_CODES){ + return _KEY_CODES[c] } return c.charCodeAt(0) } @@ -89,7 +111,7 @@ var KEYBOARD_HANDLER_PROPAGATE = true * * can be: * - explicit key code - * - key name, if present in SPECIAL_KEYS) + * - key name, if present in _SPECIAL_KEYS) * - key char (uppercase), as is returned by String.fromCharCode(...) * *