0

I have a requirement to check if the user is active or inactive in UI5. So I need to call a function when there is some kind of user events. I have done it as follows. But is there a better way without listing the events as below?

**

jQuery(document).on("blur focus click dblclick mousedown mouseup mouseover mouseout etc", function(oEvent) {
    //call some function
    }

**

AngularDev
  • 23
  • 4

3 Answers3

1

You do not to listen to all those events. These are enough.

$(document).on("scroll mouseover mouseup focus blur", (event) => {
  console.log("User interaction", event.originalEvent)
})

You also need to listen to these events:

  keydown
  resize
  auxclick 

   $(document).on("scroll mouseover mouseup focus blur keydown auxclick", (event) => {
      console.log("User interaction", event.originalEvent)
    })

   $(window).on("resize", (event) => {
      console.log("User interaction", event.originalEvent)
    })
mahan
  • 12,366
  • 5
  • 48
  • 83
0

It's hard to prove a negative, but no, I'm pretty sure there's no "catch all" event handler mechanism. If there were, it would be likely mentioned in the MDN documentation for addEventListener and/or the specification.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
0

There is currently no way to do so.

By doing that, your code would be flooded with an amount of events really hard to manage, and performances (and responsiveness) would be very low.

However, this question has been more or less answered recently. Please refer to https://stackoverflow.com/a/68426949/18860952 or https://stackoverflow.com/a/48388878/18860952