//Controller
I would like an element like drag and drop using an input text element that you can give focus but do note that I am weird and therefore, I am not sure others would like this.
Anyways, when selected I would like you to be able to press a key and this key is added as event then you can select a function that triggers when that key is pressed as shown in the image.
This is possible but this would make doing this a lot easier.
//Cheat
I added the setFocus() function because sometimes a certain interaction with your website will make it lose focus and then the keyboard inputs won’t be detected.
//To use this
Drag and drop an input text element, set it as small as possible and pin it to the page and set it off the screen and rename it controller.
Call setFocus() in your code and add a onKeyPress listener to the focuser_keyPress function.
//Concept code (needs some adapting)
let active = true;
let detector;
export function controller_keyPress(event) {
let key = event.key;
if (active === true) {
switch (key) {case 'A':
//DoSomething
break;
case ‘ArrowRight’:
//DoSomething
break;
}
}}
function setFocus() {
detector = setInterval(function () {
if ((active === true)) {
$w(‘#controller’).focus();
}else{
clearInterval(detector)
}
}, 100);
}