Keyboard NOKIA
About
Theย NOKIA Keyboard embraces the iconic layout synonymous with NOKIA phones to enter letters (and numbers). For instance, to type the letter โE,โ press the third button twice. The illustration below shows how much times you have to push a button quickly to get a letter.

The code:
let separatorAfter, separatorTimeout, separatorLength = 1;
let submitAfter, submitTimeout;
let decimalMarker = 0; // language based
let lastCharLength = 1;
let lastAutoSeparator = false;
let actualValue = โโ;
function main() {
let separator = config.get(โkeyboard.separator.keyโ);
if (strCharAt(separator, 1) !== โ#โ) separatorLength = strLen(separator);
separatorAfter = config.get(โkeyboard.separator.afterโ);
submitAfter = config.get(โkeyboard.submit.afterโ)
ps.connect();
resetValue();
}
function resetValue() {
actualValue = โโ;
}
function peekValue() {
ps.print(actualValue);
}
function sendSeparator(charLength) {
keyboard.send(โ#SEPARATORโ);
resetValue();
lastCharLength = separatorLength + charLength;
actualValue = โโ;
}
function sendSubmit() {
if (lastAutoSeparator) {
for (let i = 0; i < separatorLength; i++) {
keyboard.send(โ#BSโ);
}
}
keyboard.send(โ#SUBMITโ);
lastCharLength = 1;
actualValue = โโ;
atom.vibrate(โ.โ);
}
let mapping = [
, , ,
, , ,
, , ,
, ,
];
function handleAfter() {
peekValue();
lastAutoSeparator = false;
if (separatorAfter > 0) {
if (separatorAfter < 99) { // after x character
if (strLen(actualValue) >= separatorAfter) {
lastAutoSeparator = true;
sendSeparator(lastCharLength);
}
} else {
clearTimeout(separatorTimeout);
separatorTimeout = setTimeout(function() {
lastAutoSeparator = true;
sendSeparator(lastCharLength);
}, separatorAfter);
}
}
if (submitAfter > 0) {
if (separatorAfter < 99) { // after x character
clearTimeout(submitTimeout);
}
}
}
function handleKey(key) {
if (keyboard.isSubmit(key)) {
sendSubmit();
return;
}
if (keyboard.isCharacter(key)) {
keyboard.send(key);
lastCharLength = strLen(key);
actualValue += key;
handleAfter();
return;
}
if (keyboard.isBackspace(key)) {
for (let i = 0; i < lastCharLength; i++) {
keyboard.send(key);
actualValue = strSub(actualValue, 0, -1);
}
lastCharLength = 1;
handleAfter();
return;
}
if (keyboard.isSeparator(key)) {
sendSeparator(0);
handleAfter();
}
}
function onAtomButtonClick(keyCode, count) {
let key = mapping;
if (typeof key === โstringโ && strCharAt(key, 0) !== โ#โ) {
if (strLen(key) >= count + 1) {
key = strCharAt(key, count);
} else {
return;
}
}
handleKey(key);
}
function onAtomButtonLongPress(keyCode) {
let key = mapping;
handleKey(key);
}
function onAtomButtonRepeatPress(keyCode) {
let key = mapping;
handleKey(key);
}
function onEvent(e) {
if (e.source === โatom:buttonโ) {
const buttonId = parseInt(e.value);
if (e.type === โclickโ) {
return onAtomButtonClick(buttonId, 0);
}
if (e.type === โlongpressโ) {
return onAtomButtonLongPress(buttonId);
}
if (e.type === โrepeatpressโ) {
return onAtomButtonRepeatPress(buttonId);
}
if (strSub(e.type, 0, 5) === โclickโ && strLen(e.type) === 6) {
let clickCount = parseInt(strCharAt(e.type, 5));
onAtomButtonClick(buttonId, clickCount - 1);
}
}
}