input.js (1309B)
1 // maybe add a configuration option for this later 2 const keys = ["j", "k", "l"]; 3 const hintkey = "h"; 4 const blindkey = "b"; 5 const deletechar = String.fromCharCode(127); 6 7 /* pressed is an array of pressed indizes from one gesture */ 8 function pressed2gesture(pressed, full) { 9 if (full) return 10; 10 if (pressed.length == 1) return pressed[0] + 7; 11 else { 12 let m = [ 13 [0, 1, 5], 14 [2, 0, 3], 15 [6, 4, 0] 16 ]; 17 return m[pressed[0]][pressed[1]]; 18 } 19 } 20 21 // returns false if gestures are not enough to create a character 22 function gestures2char(gestures) { 23 if (gestures.length == 0) return false; 24 let lastg = gestures[gestures.length - 1]; 25 if (lastg >= 7) { 26 switch (lastg) { 27 case 7: 28 return " "; 29 case 8: 30 return "-"; 31 case 9: 32 return "."; 33 case 10: 34 return deletechar; 35 default: 36 return false; 37 } 38 } 39 let m = [ 40 "abcdef", 41 "ghijkl", 42 "mnopqr", 43 "stuvwx", 44 "yz0123", 45 "456789" 46 ]; 47 return m[gestures[0] - 1][gestures[1] - 1]; 48 } 49 50 51 module.exports = { 52 keys, 53 hintkey, 54 blindkey, 55 deletechar, 56 pressed2gesture, 57 gestures2char 58 }