// Code Snippet for simulating SoftKeys (LSK, RSK) by using Ctrl+ArrowKey
function softkey(e) {
const { target, key, bubbles, cancelable, repeat, type } = e;
if (!/Left|Right/.test(key) || !key.startsWith("Arrow") || !e.ctrlKey) return;
e.stopImmediatePropagation();
e.stopPropagation();
e.preventDefault();
target.dispatchEvent(new KeyboardEvent(type, { key: "Soft" + key.slice(5), bubbles, cancelable, repeat }));
}
document.addEventListener("keyup", softkey, true);
document.addEventListener("keydown", softkey, true);
// this is basically the same thing as above, but we modify the KeyboardEvent prototype instead of binding events
const KeyboardEvent_key_property = Object.getOwnPropertyDescriptor(KeyboardEvent.prototype, "key");
Object.defineProperty(KeyboardEvent.prototype, "key", {
enumerable: true,
configurable: true,
get() {
const evt_key = KeyboardEvent_key_property.get.call(this);
if (
this.ctrlKey &&
evt_key.startsWith("Arrow") &&
(evt_key.endsWith("Left") || evt_key.endsWith("Right"))
) {
return "Soft" + evt_key.slice(5);
}
return evt_key;
},
});