I've implemented basic press triggers for my 8BitDo Micro controller in the 'Device Handling' JavaScript section. For certain buttons, I want to add a 'hold' state trigger in addition to the simple 'press' trigger. As in, when 'A' is held for less than 500-1000ms or so, the function sends trigger 'A (Press)'; when it's held for more, the function sends trigger 'A (Hold)'.
Only I can't see how this is possible. As the script is run on each event, there's no way to record or retrieve past events. Right? Or am I missing something? Is there another way of achieving what I want to do?
You'd need to maintain button state in static variables outside of the function and make use of bttGetNextEvenWithoutChange() so that your analyzeDeviceInput() function keeps getting called again and again. See e.g. Generic Devices: Report repeated events even if monitored bytes don't change for some discussion.
Ah, for some reason I'd assumed the editable script was isolated or siloed off somehow, or that only the function was called. Thanks, will take another look at it