-
Notifications
You must be signed in to change notification settings - Fork 0
/
keyboard_layout.js
52 lines (43 loc) · 1.34 KB
/
keyboard_layout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function rowOf() {
var row = [];
for (var i = 0; i < arguments.length; i++) {
if (typeof arguments[i] === 'string') {
// console.log(arguments[i]);
const keys = arguments[i].split('');
// console.log(keys);
row.push.apply(row, arguments[i].split(''));
}
else if (typeof arguments[i] === 'object') {
// array
row.push.apply(row, arguments[i]);
} else {
row.push(arguments[i]);
}
// console.log(row);
}
return row;
}
function AmericanKeyboardLayout() {
this.map = {};
this.initMapping();
}
AmericanKeyboardLayout.prototype.positionOf = function(key) {
return this.map[key];
};
AmericanKeyboardLayout.prototype.addRow = function(row, keysFromLeftToRight) {
this.map = keysFromLeftToRight.reduce((M, key, col) => {
M[key] = {row: row, col: col};
return M;
}, this.map);
};
AmericanKeyboardLayout.prototype.initMapping = function() {
this.addRow(4, rowOf('!@#$%^*()_+'));
this.addRow(4, rowOf('§1234567890-=', ["Backspace"]));
this.addRow(3, rowOf(undefined, 'QWERTYUIOP{}'));
this.addRow(3, rowOf('\t', 'qwertyuiop[]'));
this.addRow(2, rowOf(undefined, 'ASDFGHJKL:"|'));
this.addRow(2, rowOf(undefined, 'asdfghjkl;','\'','\\'));
this.addRow(1, rowOf(undefined,'~ZXCVBNM<>?'));
this.addRow(1, rowOf(undefined,'`zxcvbnm,./'));
this.addRow(0, rowOf(undefined, undefined, undefined, undefined, undefined,' '));
};