How to Detect Mouse Button Down and Mouse Button Up Events

Dec 01, 2017

I would like to be able to detect mouse down and mouse up events.  Want to determine if a user pressed a control and held it down for 3 seconds before releasing the control.  On the surface the existing Storyline Events seem inadequate to accomplish what I need.

Anybody have a way to detect mouse down and mouse up events?

4 Replies
Rachael Mordecai

I know this is an old thread, but hopefully this is helpful to someone. It is possible to detect a mouse 'click' or a 'mousedown' or any other DOM event using Javascript. In the example below I asked the module to listen out for 'mousedown' and if the target was the scrollbar then some variable in Storyline is adjusted. 

document.addEventListener('mousedown', function(e) {
      let myClass = e.target.className;
      //console.log(myClass);
      if (myClass === 'scrollarea-btn') {
            var player = GetPlayer();
              player.SetVar("monitor_panel_click",true);
      }
});
Stefan K

Hi Simon,

I am also looking for a solution for "Mouse Button up", so that some event is triggered when the mouse button is release while the mouse is positioned over a specific object.

I guess the JS should look like below. But what I don't understand: How do I figure out what class my object is?

It is not the name of my object, or is it? I tried using that in the attached test project.

 

document.addEventListener('mouseup', function(e) {
      let myClass = e.target.className;
      //console.log(myClass);
      if (myClass === 'scrollarea-btn') {
            var player = GetPlayer();
              player.SetVar("monitor_panel_click",true);
      }
});