@@ -56,35 +56,53 @@ StringBuilder.prototype = {
5656/////////////////////////////////////////////////////////////////////////////
5757// class KeyboardMapper
5858//
59- function KeyboardMapper ( nativeKeypress , keyCodeMap , charCodeMap , shiftedCharCodeMap ) {
59+ function KeyboardMapper ( nativeKeypress , keyCodeMap , shiftedKeyCodeMap , charCodeMap , shiftedCharCodeMap ) {
6060 this . nativeKeypress = nativeKeypress ;
6161 this . keyCodeMap = keyCodeMap ;
62+ this . shiftedKeyCodeMap = shiftedKeyCodeMap ;
6263 this . charCodeMap = charCodeMap ;
6364 this . shiftedCharCodeMap = shiftedCharCodeMap ;
6465}
6566
6667KeyboardMapper . prototype = {
67- nativeKeypress : function ( ) {
68+ supportNativeKeypress : function ( ) {
6869 return this . nativeKeypress ;
6970 } ,
7071
71- mapKeyCode : function ( code , modifier ) {
72- if ( this . keyCodeMap && this . keyCodeMap [ code ] )
73- return this . keyCodeMap [ code ] ;
72+ mapKeyCode : function ( code , modifiers ) {
73+ if ( ( modifiers & AjaxViewer . SHIFT_KEY ) != 0 ) {
74+ if ( this . shiftedKeyCodeMap && this . shiftedKeyCodeMap [ code ] ) {
75+ g_logger . log ( Logger . LEVEL_INFO , "map SHIFTED keycode " + code + " to " + this . shiftedKeyCodeMap [ code ] + ", modifiers: " + modifiers + ', char: ' + String . fromCharCode ( code ) ) ;
76+ return this . shiftedKeyCodeMap [ code ] ;
77+ } else {
78+ g_logger . log ( Logger . LEVEL_INFO , "map SHIFTED keycode " + code + " to " + code + ", modifiers: " + modifiers + ', char: ' + String . fromCharCode ( code ) ) ;
79+ }
80+ } else {
81+ if ( this . keyCodeMap && this . keyCodeMap [ code ] ) {
82+ g_logger . log ( Logger . LEVEL_INFO , "map keycode " + code + " to " + this . keyCodeMap [ code ] + ", modifiers: " + modifiers + ', char: ' + String . fromCharCode ( code ) ) ;
83+ return this . keyCodeMap [ code ] ;
84+ } else {
85+ g_logger . log ( Logger . LEVEL_INFO , "map keycode " + code + " to " + code + ", modifiers: " + modifiers + ', char: ' + String . fromCharCode ( code ) ) ;
86+ }
87+ }
7488
7589 return code ;
7690 } ,
7791
78- mapCharCode : function ( code , modifier ) {
79- if ( ( modifier & AjaxViewer . SHIFT_KEY ) != 0 ) {
80- if ( this . shiftedCharCodeMap && this . shiftedCharCodeMap [ code ] )
92+ mapCharCode : function ( code , modifiers ) {
93+ if ( ( modifiers & AjaxViewer . SHIFT_KEY ) != 0 ) {
94+ if ( this . shiftedCharCodeMap && this . shiftedCharCodeMap [ code ] ) {
95+ g_logger . log ( Logger . LEVEL_INFO , "map SHIFTED keycode " + code + " to charcode " + this . shiftedCharCodeMap [ code ] + ", modifiers: " + modifiers + ', char: ' + String . fromCharCode ( code ) ) ;
8196 return this . shiftedCharCodeMap [ code ] ;
97+ }
8298 } else {
83- if ( this . charCodeMap && this . charCodeMap [ code ] )
99+ if ( this . charCodeMap && this . charCodeMap [ code ] ) {
100+ g_logger . log ( Logger . LEVEL_INFO , "map keycode " + code + " to charcode " + this . shiftedCharCodeMap [ code ] + ", modifiers: " + modifiers + ', char: ' + String . fromCharCode ( code ) ) ;
84101 return this . charCodeMap [ code ] ;
102+ }
85103 }
86104
87- return code ;
105+ return undefined ;
88106 }
89107} ;
90108
@@ -303,10 +321,27 @@ AjaxViewer.prototype = {
303321 } ,
304322
305323 setupKeyboardTranslationTable : function ( ) {
306- this . keyboardTables = [ ] ;
324+ this . keyboardMappers = [ ] ;
325+ this . keyboardMappers [ AjaxViewer . KEYBOARD_TYPE_ENGLISH ] = new KeyboardMapper ( true , null , null , null , null ) ;
326+
327+ var keyCodeMap = [ ] ;
328+ var shiftedKeyCodeMap = [ ] ;
329+ var charCodeMap = [ ] ;
330+ var shiftedCharCodeMap = [ ] ;
331+
332+ shiftedKeyCodeMap [ 50 ] = 222 ; // EN 2/@ -> JP 2/"
333+ shiftedCharCodeMap [ 50 ] = 34 ;
334+
335+ shiftedKeyCodeMap [ 54 ] = 55 ; // EN 6/^ -> JP 6/&
336+ shiftedCharCodeMap [ 94 ] = 38 ;
337+
307338
308- this . keyboardMappers [ AjaxViewer . KEYBOARD_TYPE_JAPANESE ] = new KeyboardMapper ( true , null , null , null ) ;
309- this . keyboardMappers [ AjaxViewer . KEYBOARD_TYPE_JAPANESE ] = new KeyboardMapper ( true , null , null , null ) ;
339+ this . keyboardMappers [ AjaxViewer . KEYBOARD_TYPE_JAPANESE ] = new KeyboardMapper ( false , keyCodeMap , shiftedKeyCodeMap ,
340+ charCodeMap , shiftedCharCodeMap ) ;
341+ } ,
342+
343+ getCurrentKeyboardMapper : function ( ) {
344+ return this . keyboardMappers [ this . currentKeyboard ] ;
310345 } ,
311346
312347 setupUIController : function ( ) {
@@ -328,13 +363,18 @@ AjaxViewer.prototype = {
328363 }
329364 ) ;
330365
331- $ ( "#toolbar" ) . find ( "a ") . each ( function ( i , val ) {
366+ $ ( "[cmd]" , "#toolbar ") . each ( function ( i , val ) {
332367 $ ( val ) . click ( function ( e ) {
333- var cmdLink = $ ( e . target ) . closest ( "a" ) ;
334-
335- if ( cmdLink . attr ( "cmd" ) ) {
336- var cmd = cmdLink . attr ( "cmd" ) ;
337- ajaxViewer . onCommand ( cmd ) ;
368+ var cmd = $ ( e . target ) . attr ( "cmd" ) ;
369+ if ( cmd )
370+ ajaxViewer . onCommand ( cmd ) ;
371+ else {
372+ var cmdLink = $ ( e . target ) . closest ( "a" ) ;
373+
374+ if ( cmdLink . attr ( "cmd" ) ) {
375+ var cmd = cmdLink . attr ( "cmd" ) ;
376+ ajaxViewer . onCommand ( cmd ) ;
377+ }
338378 }
339379 } ) ;
340380 } ) ;
@@ -355,6 +395,13 @@ AjaxViewer.prototype = {
355395 this . sendKeyboardEvent ( AjaxViewer . KEY_DOWN , 27 , AjaxViewer . CTRL_KEY ) ;
356396 this . sendKeyboardEvent ( AjaxViewer . KEY_UP , 27 , AjaxViewer . CTRL_KEY ) ;
357397 this . sendKeyboardEvent ( AjaxViewer . KEY_UP , 17 , 0 ) ;
398+ } else if ( cmd == "toggle_logwin" ) {
399+ if ( ! g_logger . isOpen ( ) ) {
400+ g_logger . enable ( true ) ;
401+ g_logger . open ( ) ;
402+ } else {
403+ g_logger . close ( ) ;
404+ }
358405 }
359406 } ,
360407
@@ -923,7 +970,11 @@ AjaxViewer.prototype = {
923970 var ajaxViewer = this ;
924971 var target = $ ( document ) ;
925972
926- target . keypress ( function ( e ) {
973+ target . keypress ( function ( e ) {
974+ var keyboardMapper = ajaxViewer . getCurrentKeyboardMapper ( ) ;
975+ if ( ! keyboardMapper . supportNativeKeypress ( ) )
976+ return true ;
977+
927978 ajaxViewer . onKeyPress ( e . which , ajaxViewer . getKeyModifiers ( e ) ) ;
928979
929980 e . stopPropagation ( ) ;
@@ -935,7 +986,15 @@ AjaxViewer.prototype = {
935986 } ) ;
936987
937988 target . keydown ( function ( e ) {
938- ajaxViewer . onKeyDown ( e . which , ajaxViewer . getKeyModifiers ( e ) ) ;
989+ var keyboardMapper = ajaxViewer . getCurrentKeyboardMapper ( ) ;
990+
991+ ajaxViewer . onKeyDown ( keyboardMapper . mapKeyCode ( e . which , ajaxViewer . getKeyModifiers ( e ) ) , ajaxViewer . getKeyModifiers ( e ) ) ;
992+
993+ if ( ! keyboardMapper . supportNativeKeypress ( ) ) {
994+ var charCode = keyboardMapper . mapCharCode ( e . which , ajaxViewer . getKeyModifiers ( e ) ) ;
995+ if ( charCode )
996+ ajaxViewer . onKeyPress ( charCode , ajaxViewer . getKeyModifiers ( e ) ) ;
997+ }
939998
940999 e . stopPropagation ( ) ;
9411000 if ( ajaxViewer . requiresDefaultKeyProcess ( e ) )
0 commit comments