Is there a way to change state on keypress?
April 16, 2022
Is there a way to change state on keypress?
April 16, 2022
Newbie 1 posts
Followers: 0 people

I’ve used an image as a button with the action “play audio”  I’ve mapped a keystroke to the button, but would like to have it change state when I press the key.  Any help would be most appreciated!

All Comments
Sort by:  Most Recent
Apr 19, 2022
Apr 19, 2022

I had a similar query on doing this with JavaScript on a different thread as a comment but this thread (which I am seeing for the first time as I type this)  seems to have more activity.

I went with making a button set to play the audio and then adding an event listener for both the keydown and keyup events. The event listener is tied to a specific key so it can be easily swapped for a different key.

I also created a “hidden” button to perform a stop triggered audio action so that that you could have the effect of pressing the key and holding to listen to the audio and when you release the button, the audio stops.

Code attached.

Attachment

Like
()
Apr 19, 2022
Apr 19, 2022

Here is what you could do. You could add a shortcut key to each button in the properties inspector. Add a custom state to each button you wish to behave this way. The custom button would have whatever appearance you want the selected state to be. Write an advanced action that changes the state of the button to selected, plays the audio recording. Next add the action delay next action by [the length of audio clip] and finally change the state of the button back to normal. If I understand what you are trying to accomplish this should do it for you.

 

Like
()
Apr 18, 2022
Apr 18, 2022

Thank you so much!  I’m hoping to have it play the audio and switch states on keypress(not keyup) and have it switch back to the original state on keyup.  I’m also hoping to have the audio play so that is doesnt cut off if another button is pressed.  Is this possible?

Like
()
(3)
Apr 18, 2022
Apr 18, 2022
>
James K 85
's comment

Captivate only has the possibility to trigger an action on release of a pressed button. If you want more events to trigger actions you’ll need to create those events with Javascript or with InfoSemantic’s CpExtra widget (external widget, not free).

As for the audio: an audio clip started with the command ‘Play Audio’ can only be stopped by another command ‘Stop Triggered Audio’ or by starting another audio clip with ‘Play Audio’. It will not cut off in any other situation. More info in this blog:

Pausing Timeline and Audio clips – eLearning (adobe.com)

Like
()
Apr 18, 2022
Apr 18, 2022
>
Lieve Weymeis
's comment

Thank you so much for your reply!

Like
()
Apr 19, 2022
Apr 19, 2022
>
James K 85
's comment

You’re welcome. Forgot to tell that InfoSemantics offers a trial version of CpExtra. It is a great widget with tons of features, one of the best I ever used in my long Captivate career.

Like
()