Add: KeyMapper
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
class KeyTextData {
|
||||
|
||||
constructor(normalText, shiftText, shiftHandSide) {
|
||||
this.normalText = normalText;
|
||||
this.shiftText = shiftText;
|
||||
this.shiftHandSide = shiftHandSide;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
KeyTextData.HAND_LEFT = 0;
|
||||
KeyTextData.HAND_RIGHT = 1;
|
||||
|
||||
KeyTextData.THUMB = 0;
|
||||
KeyTextData.INDEX_FINGER = 1;
|
||||
KeyTextData.MIDDLE_FINGER = 2;
|
||||
KeyTextData.RING_FINGER = 3;
|
||||
KeyTextData.LITTLE_FINGER = 4;
|
||||
|
||||
KeyTextData.LEFT_HAND = 0;
|
||||
KeyTextData.RIGHT_HAND = 1;
|
||||
KeyTextData.BOTH_HAND = 2;
|
||||
KeyTextData.NONE_HAND = 3;
|
||||
|
||||
|
||||
|
||||
class KeyMapper {
|
||||
|
||||
constructor() {
|
||||
this.keyboardKeyMap = {};
|
||||
this.inputKeyMap = {};
|
||||
|
||||
this.registerKeyTextData("`", "`", "~", KeyTextData.RIGHT_HAND);
|
||||
this.registerKeyTextData("1", "1", "!", KeyTextData.RIGHT_HAND);
|
||||
this.registerKeyTextData("2", "2", "@", KeyTextData.RIGHT_HAND);
|
||||
this.registerKeyTextData("3", "3", "#", KeyTextData.RIGHT_HAND);
|
||||
this.registerKeyTextData("4", "4", "$", KeyTextData.RIGHT_HAND);
|
||||
this.registerKeyTextData("5", "5", "%", KeyTextData.RIGHT_HAND);
|
||||
this.registerKeyTextData("6", "6", "^", KeyTextData.LEFT_HAND);
|
||||
this.registerKeyTextData("7", "7", "&", KeyTextData.LEFT_HAND);
|
||||
this.registerKeyTextData("8", "8", "*", KeyTextData.LEFT_HAND);
|
||||
this.registerKeyTextData("9", "9", "(", KeyTextData.LEFT_HAND);
|
||||
this.registerKeyTextData("0", "0", ")", KeyTextData.LEFT_HAND);
|
||||
this.registerKeyTextData("-", "-", "_", KeyTextData.LEFT_HAND);
|
||||
this.registerKeyTextData("=", "=", "+", KeyTextData.LEFT_HAND);
|
||||
this.registerKeyTextData("backspace", "backspace", "backspace", KeyTextData.NONE_HAND);
|
||||
|
||||
this.registerKeyTextData("tab", "tab", "tab", KeyTextData.NONE_HAND);
|
||||
this.registerKeyTextData("[", "[", "{", KeyTextData.LEFT_HAND);
|
||||
this.registerKeyTextData("]", "]", "}", KeyTextData.LEFT_HAND);
|
||||
this.registerKeyTextData("\\", "\\", "|", KeyTextData.LEFT_HAND);
|
||||
|
||||
this.registerKeyTextData("caps_lock", "caps lock", "caps lock", KeyTextData.NONE_HAND);
|
||||
this.registerKeyTextData(";", ";", ":", KeyTextData.LEFT_HAND);
|
||||
this.registerKeyTextData("'", "'", "\"", KeyTextData.LEFT_HAND);
|
||||
this.registerKeyTextData("enter", "enter", "enter", KeyTextData.NONE_HAND);
|
||||
|
||||
this.registerKeyTextData("left_shift", "left_shift", "left_shift", KeyTextData.LEFT_HAND);
|
||||
this.registerKeyTextData("right_shift", "right_shift", "right_shift", KeyTextData.RIGHT_HAND);
|
||||
this.registerKeyTextData(",", ",", "<", KeyTextData.LEFT_HAND);
|
||||
this.registerKeyTextData(".", ".", ">", KeyTextData.LEFT_HAND);
|
||||
this.registerKeyTextData("/", "/", "?", KeyTextData.LEFT_HAND);
|
||||
|
||||
this.registerKeyTextData("left_ctrl", "ctrl", "ctrl", KeyTextData.NONE_HAND);
|
||||
this.registerKeyTextData("window", "window", "window", KeyTextData.NONE_HAND);
|
||||
this.registerKeyTextData("left_alt", "alt", "alt", KeyTextData.NONE_HAND);
|
||||
this.registerKeyTextData("chinese", "한자", "한자", KeyTextData.NONE_HAND);
|
||||
this.registerKeyTextData("space", "space", "space", KeyTextData.BOTH_HAND);
|
||||
this.registerKeyTextData("korean_english", "한/영", "한/영", KeyTextData.NONE_HAND);
|
||||
this.registerKeyTextData("right_alt", "alt", "alt", KeyTextData.NONE_HAND);
|
||||
this.registerKeyTextData("right_ctrl", "ctrl", "ctrl", KeyTextData.NONE_HAND);
|
||||
}
|
||||
|
||||
registerKeyTextData(keyID, normalText, shiftText, shiftHandSide) {
|
||||
this.keyboardKeyMap[keyID] = new KeyTextData(normalText, shiftText, shiftHandSide);
|
||||
|
||||
if(this.inputKeyMap[normalText] === undefined)
|
||||
this.inputKeyMap[normalText] = keyID;
|
||||
if(this.inputKeyMap[shiftText] === undefined)
|
||||
this.inputKeyMap[shiftText] = keyID;
|
||||
}
|
||||
|
||||
|
||||
getNormalText(keyID) {
|
||||
// console.log(this.keyboardKeyMap[keyID]);
|
||||
return this.keyboardKeyMap[keyID].normalText;
|
||||
}
|
||||
|
||||
getShiftText(keyID) {
|
||||
return this.keyboardKeyMap[keyID].shiftText;
|
||||
}
|
||||
|
||||
getShiftHandSide(keyID) {
|
||||
return this.keyboardKeyMap[keyID].shiftHandSide;
|
||||
}
|
||||
|
||||
|
||||
|
||||
getKeyIDOfText(text) {
|
||||
return this.inputKeyMap[text];
|
||||
}
|
||||
|
||||
getShiftTypeOfText(text) {
|
||||
let keyID = this.getKeyIDOfText(text);
|
||||
return this.keyboardKeyMap[keyID].shiftHandSide;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user