Forum Discussion

MIkeMunger's avatar
MIkeMunger
Community Member
8 years ago

How to Detect Mouse Button Down and Mouse Button Up Events

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

  • I think you can show a layer when the state is down and hide the kayer when the object is clicked should work. 

  • 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);
          }
    });
    • StefanKoler-9fd's avatar
      StefanKoler-9fd
      Community Member

      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);
            }
      });