Copy // ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
// brief: Typing Class
// note:
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
var codelist = { 8 :[ "BackSpase" , "BackSpace" ], 9 :[ "Tab" , "Tab" ], 13 :[ "Enter" , "Enter" ], 16 :[ "Shift" , "" ], 17 :[ "Ctrl" , "" ]
, 20 :[ "" , "caps" ], 32 :[ " " , " " ], 45 :[ "-" , "=" ], 48 :[ "0" , "" ], 49 :[ "1" , "!" ], 50 :[ "2" , '"' ], 51 :[ "3" , "#" ]
, 52 :[ "4" , "$" ], 53 :[ "5" , "%" ], 54 :[ "6" , "&" ], 55 :[ "7" , "'" ], 56 :[ "8" , "(" ], 57 :[ "9" , ")" ], 58 :[ ":" , "*" ]
, 59 :[ ";" , "+" ], 61 :[ ";" , "+" ], 64 :[ "@" , "`" ], 65 :[ "a" , "A" ], 66 :[ "b" , "B" ], 67 :[ "c" , "C" ], 68 :[ "d" , "D" ]
, 69 :[ "e" , "E" ], 70 :[ "f" , "F" ], 71 :[ "g" , "G" ], 72 :[ "h" , "H" ], 73 :[ "i" , "I" ], 74 :[ "j" , "J" ], 75 :[ "k" , "K" ]
, 76 :[ "l" , "L" ], 77 :[ "m" , "M" ], 78 :[ "n" , "N" ], 79 :[ "o" , "O" ], 80 :[ "p" , "P" ], 81 :[ "q" , "Q" ], 82 :[ "r" , "R" ]
, 83 :[ "s" , "S" ], 84 :[ "t" , "T" ], 85 :[ "u" , "U" ], 86 :[ "v" , "V" ], 87 :[ "w" , "W" ], 88 :[ "x" , "X" ], 89 :[ "y" , "Y" ]
, 90 :[ "z" , "Z" ], 92 :[ " \\ " , "_" ], 96 :[ "0" , "" ], 97 :[ "1" , "" ], 98 :[ "2" , "" ], 99 :[ "3" , "" ], 100 :[ "4" , "" ], 101 :[ "5" , "" ]
, 102 :[ "6" , "" ], 103 :[ "7" , "" ], 104 :[ "8" , "" ], 105 :[ "9" , "" ], 107 :[ ";" , "+" ], 109 :[ "-" , "=" ], 160 :[ "^" , "~" ]
, 173 :[ "-" , "=" ], 186 :[ ":" , "*" ], 187 :[ ";" , "+" ], 188 :[ "," , "<" ], 189 :[ "-" , "=" ], 190 :[ "." , ">" ], 191 :[ "/" , "?" ]
, 192 :[ "@" , "`" ], 219 :[ "[" , "{" ], 220 :[ " \\ " , "_" ], 221 :[ "]" , "}" ], 222 :[ "^" , "~" ], 226 :[ " \\ " , "_" ], 222 :[ "^" , "~" ]
, 240 :[ "英数" , "" ], 244 :[ "半/全" , "" ]};
var capslist = { 8 :[ "BackSpase" , "BackSpace" ], 9 :[ "Tab" , "Tab" ], 13 :[ "Enter" , "Enter" ], 16 :[ "Shift" , "" ], 17 :[ "Ctrl" , "" ]
, 20 :[ "" , "caps" ], 32 :[ " " , " " ], 45 :[ "-" , "=" ], 48 :[ "0" , "" ], 49 :[ "1" , "!" ], 50 :[ "2" , '"' ], 51 :[ "3" , "#" ]
, 52 :[ "4" , "$" ], 53 :[ "5" , "%" ], 54 :[ "6" , "&" ], 55 :[ "7" , "'" ], 56 :[ "8" , "(" ], 57 :[ "9" , ")" ], 58 :[ ":" , "*" ]
, 59 :[ ";" , "+" ], 61 :[ ";" , "+" ], 64 :[ "@" , "`" ], 65 :[ "A" , "a" ], 66 :[ "B" , "b" ], 67 :[ "C" , "c" ], 68 :[ "D" , "d" ]
, 69 :[ "E" , "e" ], 70 :[ "F" , "f" ], 71 :[ "G" , "g" ], 72 :[ "H" , "h" ], 73 :[ "I" , "i" ], 74 :[ "J" , "j" ], 75 :[ "K" , "k" ]
, 76 :[ "L" , "l" ], 77 :[ "M" , "m" ], 78 :[ "N" , "n" ], 79 :[ "O" , "o" ], 80 :[ "P" , "p" ], 81 :[ "Q" , "q" ], 82 :[ "R" , "r" ]
, 83 :[ "S" , "s" ], 84 :[ "T" , "t" ], 85 :[ "U" , "u" ], 86 :[ "V" , "v" ], 87 :[ "W" , "w" ], 88 :[ "X" , "x" ], 89 :[ "Y" , "y" ]
, 90 :[ "Z" , "z" ], 92 :[ " \\ " , "_" ], 96 :[ "0" , "" ], 97 :[ "1" , "" ], 98 :[ "2" , "" ], 99 :[ "3" , "" ], 100 :[ "4" , "" ], 101 :[ "5" , "" ]
, 102 :[ "6" , "" ], 103 :[ "7" , "" ], 104 :[ "8" , "" ], 105 :[ "9" , "" ], 107 :[ ";" , "+" ], 109 :[ "-" , "=" ], 160 :[ "^" , "~" ]
, 173 :[ "-" , "=" ], 186 :[ ":" , "*" ], 187 :[ ";" , "+" ], 188 :[ "," , "<" ], 189 :[ "-" , "=" ], 190 :[ "." , ">" ], 191 :[ "/" , "?" ]
, 192 :[ "@" , "`" ], 219 :[ "[" , "{" ], 220 :[ " \\ " , "_" ], 221 :[ "]" , "}" ], 222 :[ "^" , "~" ], 226 :[ " \\ " , "_" ], 222 :[ "^" , "~" ]
, 240 :[ "英数" , "" ], 244 :[ "半/全" , "" ]};
var leftcode = { "!" : "" , '"' : "" , "#" : "" , "$" : "" , "%" : "" , "&" : "" , "Q" : "" , "W" : "" , "E" : "" , "R" : "" , "T" : "" , "A" : "" , "S" : ""
, "D" : "" , "F" : "" , "G" : "" , "Z" : "" , "X" : "" , "C" : "" , "V" : "" , "B" : "" };
var leftcaps = { "!" : "" , '"' : "" , "#" : "" , "$" : "" , "%" : "" , "&" : "" , "q" : "" , "w" : "" , "e" : "" , "r" : "" , "t" : "" , "a" : "" , "s" : ""
, "d" : "" , "f" : "" , "g" : "" , "z" : "" , "x" : "" , "c" : "" , "v" : "" , "b" : "" };
var eachactive = { " \\ " : "220" , "|" : "220" , "_" : "226" , ";" : "187" , "+" : "187" , ":" : "186" , "*" : "186" };
var keyboardHTML = ''
+ '<table id="keyboard">'
+ '<tr class="t r
_k "> '
+ ' <td class="key top1" id="left_20"><span id="caps_20" class="off">caps</span></td>'
+ ' <td class="key top1" id="key_49">1</td>'
+ ' <td class="key top1" id="key_50">2</td>'
+ ' <td class="key top1" id="key_51">3</td>'
+ ' <td class="key top1" id="key_52">4</td>'
+ ' <td class="key top1" id="key_53">5</td>'
+ ' <td class="key top1" id="key_54">6</td>'
+ ' <td class="key top1" id="key_55">7</td>'
+ ' <td class="key top1" id="key_56">8</td>'
+ ' <td class="key top1" id="key_57">9</td>'
+ ' <td class="key top1" id="key_48">0</td>'
+ ' <td class="key top1" id="key_189">-</td>'
+ ' <td class="key top1" id="key_187">=</td>'
+ ' <td class="key top1" id="right_8"><span id="backspase_8">BackSpase</span></td>'
+ '</tr>'
+ '<tr class="tr_k">'
+ ' <td class="key top2" id="tab_9"><span id="tab_9" class="off">Tab</span></td>'
+ ' <td class="key top2" id="key_81">Q</td>'
+ ' <td class="key top2" id="key_87">W</td>'
+ ' <td class="key top2" id="key_69">E</td>'
+ ' <td class="key top2" id="key_82">R</td>'
+ ' <td class="key top2" id="key_84">T</td>'
+ ' <td class="key top2" id="key_89">Y</td>'
+ ' <td class="key top2" id="key_85">U</td>'
+ ' <td class="key top2" id="key_73">I</td>'
+ ' <td class="key top2" id="key_79">O</td>'
+ ' <td class="key top2" id="key_80">P</td>'
+ ' <td class="key top2" id="key_219">[</td>'
+ ' <td class="key top2" id="key_221">]</td>'
+ ' <td class="key top2" id="key_220"><span id="yen_220"> \\ </span></td>'
+ '</tr>'
+ '<tr class="tr_k">'
+ ' <td class="key top3" id="left_16"><span id="shift_16" class="off">Shift</span></td>'
+ ' <td class="key top3" id="key_65">A</td>'
+ ' <td class="key top3" id="key_83">S</td>'
+ ' <td class="key top3" id="key_68">D</td>'
+ ' <td class="key top3" id="key_70">F</td>'
+ ' <td class="key top3" id="key_71">G</td>'
+ ' <td class="key top3" id="key_72">H</td>'
+ ' <td class="key top3" id="key_74">J</td>'
+ ' <td class="key top3" id="key_75">K</td>'
+ ' <td class="key top3" id="key_76">L</td>'
+ ' <td class="key top3" id="key_186">;</td>'
+ ' <td class="key top3" id="key_222"> \' </td>'
+ ' <td class="key top3" id="key_13"><span id="enter_13" class="off">Enter</span></td>'
+ '</tr>'
+ '<tr class="tr_k">'
+ ' <td class="key top4" id="left_240"><span id="moji_240" class="off">英数</span></td>'
+ ' <td class="key top4" id="left_17"><span id="ctrl_17" class="off">Ctrl</span></td>'
+ ' <td class="key top4" id="left_91"><span id="win_91" class="off">Win</span></td>'
+ ' <td class="key top4" id="left_244"><span id="kana_244" class="off">半/全</span></td>'
+ ' <td class="key top4" id="key_32"><span id="space_32" class="off">Space</span></td>'
+ ' <td class="key top4" id="right_91"><span id="menu_91" class="off">Menu</span></td>'
+ ' <td class="key top4" id="right_240"><span id="moji_240" class="off">英数</span></td>'
+ ' <td class="key top4" id="right_18"><span id="alt_18" class="off">Alt</span></td>'
+ ' <td class="key top4" id="left_32"><span id="space_32" class="off">Space</span></td>'
+ ' <td class="key top4" id="right_18"><span id="alt_18" class="off">Alt</span></td>'
+ '</tr>'
+ '</table>' ;
class Typing {
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
// Brief: Constructor
// Note:
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
constructor () {
this .capslock = ""
}
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
// Brief: Insert the HTML of the keyboard
// Note:
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
insertKeyboard ( id ) {
document. getElementById (id).innerHTML = keyboardHTML;
}
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
// Brief: Get the inputted character
// Note:
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
checkWord ( event ) {
var keycode, shiftcode, chara
keycode = event.keyCode;
shiftcode = event.shiftKey;
if ( this .capslock == 1 ){
chara = this . getCapsChar (keycode, shiftcode);
} else {
chara = this . getChar (keycode, shiftcode);
}
return chara;
}
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
// Brief: Check CapsLock and retrieve its state
// Note:
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
checkCapsLock ( onKeyUpEvent ) {
if (onKeyUpEvent. getModifierState ( "CapsLock" ) == false ) {
console. log ( "CapsLock OFF" );
this .capslock = 0 ;
}
else {
console. log ( "CapsLock ON" );
this .capslock = 1 ;
}
return this .capslock;
}
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
// Brief: Retrieve a character from the key code and shift state
// Note: CapsLock OFF
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
getChar ( keycode , shiftcode ){
var chara;
if (keycode in codeList){
if (shiftcode){
chara = codeList[keycode][ 1 ];
} else {
chara = codeList[keycode][ 0 ];
}
} else {
chara = "" ;
}
return chara;
}
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
// Brief: Retrieve a character from the key code and shift state
// Note: CapsLock ON
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
getCapsChar ( keycode , shiftcode ){
var chara;
if (keycode in capsList){
if (shiftcode){
chara = capsList[keycode][ 1 ];
} else {
chara = capsList[keycode][ 0 ];
}
} else {
chara = "" ;
}
return chara;
}
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
// Brief: Update the color state of the keyboard
// Note:
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
active ( statement , numOfStatement ){
var ichi = numOfStatement; // Position of the statement (which one)
var mondai = statement; // The statement
var mondaiLen = statement. length ; // Length of the statement
var left, list;
this . resetActive ();
if ( this .capslock == 1 ){
// CapsLock: ON
left = leftCaps;
list = capsList;
} else {
// CapsLock: OFF
left = leftCode;
list = codeList;
}
if (ichi != mondaiLen){
for ( var i in list){
if (list[i][ 0 ] == mondai. charAt (ichi)){
if (mondai. charAt (ichi) in eachActive){
this . setActive ( "code" + ( '00' + eachActive[mondai. charAt (ichi)]). slice ( - 3 ), 0 );
} else {
this . setActive ( "code" + ( '00' + i). slice ( - 3 ), 0 );
}
} else if (list[i][ 1 ] == mondai. charAt (ichi)){
if (mondai. charAt (ichi) == "_" ){
this . setActive ( "code226" , 0 );
} else if (mondai. charAt (ichi) == "|" ){
this . setActive ( "code220" , 0 );
} else {
this . setActive ( "code" + ( '00' + i). slice ( - 3 ), 0 );
}
if (list[i][ 1 ] in left){
this . setActive ( "code016" , 1 );
} else {
this . setActive ( "code016" , 0 );
}
}
}
}
}
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
// Brief: Apply color to the target key.
// Note: targetClass -> The class to which color will be applied
// targetNo -> If there are multiple targets to be colored, which one to color
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
setActive ( targetClass , targetNo ){
var allElements;
var elementName;
var foundElements = new Array ();
if (document.all){
allElements = document.all;
} else {
allElements = document. getElementsByTagName ( "*" );
}
var elementsLen;
var j = 0 ;
for ( var i = 0 ,elementsLen = allElements. length ;i < elementsLen;i ++ ){
elementName = allElements[i].className;
if (elementName. indexOf (targetClass, 0 ) > - 1 ) {
foundElements[j] = allElements[i];
j ++ ;
}
}
foundElements[targetNo].style.background = "#00ffff" ;
}
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
// Brief: Remove the color from the key.
// Note:
// ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
resetActive (){
var allElements;
var elementName;
if (document.all){
allElements = document.all;
} else {
allElements = document. getElementsByTagName ( "*" );
}
var elementsLen;
for ( var i = 0 ,elementsLen = allElements. length ;i < elementsLen;i ++ ){
elementName = allElements[i].className;
if (elementName. indexOf ( "table" , 0 ) > - 1 ) {
allElements[i].style.background = "#ffffff" ;
}
}
}
}