Reputation: 3
I'm developing a web app for Samsung wearable device and I would like to detect when user makes a long press on a back-hardware button.
The only information that I have found so far is this:
document.addEventListener('tizenhwkey', function(e) {...});
The problem? This event fires only when back-button is released, but unfortunately it doesn't fire when the back-button is pressed - and for detecting long press when need information when back-button is pressed and when it was released.
Any ideas how to detect a long press of back-hardware button?
Upvotes: 0
Views: 434
Reputation: 164
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:
doubleClickWaitTime
milliseconds.backButtonDoublePress()
is called.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.
Upvotes: 1
Reputation: 1
I checked the docuement. But Tizen platform does not provide a way to distinguish between press and release of hardware key.
https://docs.tizen.org/application/web/guides/tau/event-handling/
Upvotes: 0