There indeed is no way to detect a long press with Tizen Web. An alternative could be to detect a quick double-press, instead of a long press. That can be accomplished using timers.
E.g.
const doubleClickWaitTime = 400;
let doubleClickTimeout = -1;
window.addEventListener('tizenhwkey', function(ev) {
if (ev.keyName === 'back') {
if (doubleClickTimeout === -1) {
// First click of back button
doubleClickTimeout = setTimeout(() => {
doubleClickTimeout = -1;
backButtonSinglePress();
}, doubleClickWaitTime);
} else {
// Second click of back button
clearTimeout(doubleClickTimeout);
doubleClickTimeout = -1;
backButtonDoublePress();
}
}
});
function backButtonSinglePress() {
// Single press
}
function backButtonDoublePress() {
// Double press
}
This does the following:
- When the user clicks the hardware key, a timer is started that fires a function after
doubleClickWaitTime
milliseconds.
- If the user presses the hardware button again during this time, the timer is canceled, and
backButtonDoublePress()
is called.
- If the user doesn't press the hardware button again, the timer fires and executes
backButtonSinglePress()
after resetting the timer.
The doubleClickWaitTime
variable can be modified to give the user more time for a double click. However, the longer this delay, the longer a single click event takes to fire.