Skip to main content
Inspiring
April 9, 2015
Answered

Can I have an action occur only after a button / click box is clicked and held for three seconds?

  • April 9, 2015
  • 3 replies
  • 1540 views

Within Captivate, I am trying to simulate touching and holding a button for three seconds on a touch pad to get a second window to come up.  I have an image of the touchpad and an image of the second window.  Now I have to set up the interaction.  Is it possible for me to have an image "show" -- in this case, the second window -  only after a click box or button is held for three (or more) seconds?

Thanks for any help!

Ryan

This topic has been closed for replies.
Correct answer TLCMediaDesign

You could put the script in template files, I usually do that once my script is working.

This script will do what you want:

<script>
var myTime;

document.getElementById("buttonID").addEventListener("mousedown", mouseDown);
document.getElementById("buttonID").addEventListener("mouseup", mouseUp);

function mouseDown()
{
    myTime = setTimeout(function(){ cp.show("image_name"); }, 3000);
}

function mouseUp()
{
    clearTimeout(myTime);
}

</script>

3 replies

kiranr69507020
Participant
July 5, 2018

hi,

I am trying this code in the script window. It is not working. Could you please tel me where might be the mistake.

var myTime;

window.getElementById("button_18").addEventListener("mousedown", mouseDown);

window.getElementById("button_1").addEventListener("mouseup", mouseUp);

function mouseDown()

{

myTime=setTimeout(step1(),3000);

}

function step1()

{ValueX=ValueX+10;}

function mouseUp()

{

    clearTimeout(myTime);

}

TLCMediaDesign
Inspiring
July 11, 2018

What is it you are trying to do?

For one thing, you are applying the event listeners to 2 different objects, button_18 and button_1, they should be for the same object.

So your code is just incrementing a variable by 10 every 3 seconds while the mouse is down.

TLCMediaDesign
Inspiring
April 9, 2015

This may be possible if you insert some JavaScript post publishing. The button woud NOT be able to have any action applied to it.

You would need to create an event listener for the press/touch and one for the click, start a timer on press, then on click evaluate the time and show the image if over 3 seconds.

Inspiring
April 23, 2015

Hi TLCMediaDesign,

That sounds very interesting and I would like to learn how to do it. I just read Common JS interface and I know how to manipulate the output at runtime using the JS console, but that is all I really know how to do...

To understand your answer, I had to make a few assumptions.  When you say JS "post publishing", you mean going into one of the JS files that get published with the project such as standard.js and manipulating that.  Is that correct?

My second question has to do with the event listener.  I have some experience with JS in the past and manipulating HTML elements, for example.  How do I find a particular button, or any Captivate object in the JS?  HTML elements always have IDs and classes...

Thanks for any help..

TLCMediaDesign
TLCMediaDesignCorrect answer
Inspiring
April 24, 2015

You could put the script in template files, I usually do that once my script is working.

This script will do what you want:

<script>
var myTime;

document.getElementById("buttonID").addEventListener("mousedown", mouseDown);
document.getElementById("buttonID").addEventListener("mouseup", mouseUp);

function mouseDown()
{
    myTime = setTimeout(function(){ cp.show("image_name"); }, 3000);
}

function mouseUp()
{
    clearTimeout(myTime);
}

</script>

Legend
April 9, 2015

Customized touch and long press actions are not possible. But it is definitely a good feature to have.

Please raise a feature request.

https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

Sreekanth