Press & Hold Trigger for Generic Device (Device Handling JavaScript)

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.