Button::setCommandToTrigger and wantsKeyUpDownCallbacks

Hi there, I was wondering if it is possible to to use the ApplicationCommandInfo::wantsKeyUpDownCallbacks for a command that is also attached to a button.

What I’m after is a rewind/forward behaviour in my app when the user holds down a key. When there is no button attached to the command the flag works correctly and I get the ApplicationCommandTarget::InvocationInfo::isKeyDown flag passed correctly to my perform() method. However, as soon as I attach a button to it only the key down callback is called.

I understand this probably has something to do with buttons only triggering on up OR down clicks rather than both but I was wondering if it is something other people have tackled?

Hello dave96…

I am not sure, to suggest such thing to you,
Is it proper to do such functionality in mouseDown and mouseUp callbacks with Timer class’s callback? I have tried such things using these events…

Checkout the following code, Which I have got in working position.

[code]void mouseDown (const MouseEvent & e)
{
if((e.mods.isLeftButtonDown()) && (!isTimerRunning()))
{
// Forward/Rewind when nextButton/backButton is pressed for more than 500 milliseconds
if((nextButton == e.eventComponent) || (backButton == e.eventComponent))
if(isSongPlaying())
startTimer(500);
}
}

void mouseUp (const MouseEvent & e)
{
if((e.mods.isLeftButtonDown()) && (isTimerRunning()))
{
// nextButton released
if(nextButton == e.eventComponent)
{
stopTimer();
// Check whether we need to jump over the next track or simply stop forwarding
if(e.getLengthOfMousePress() < 500)
nextClicked();
}
// backButton released
else if(backButton == e.eventComponent)
{
stopTimer();
// Check whether we need to jump over the previous track or simply stop rewinding
if(e.getLengthOfMousePress() < 500)
backClicked();
}
}
}

void timerCallback ()
{
// Increase the timer interval to avoid excess position shift
startTimer(1000);
if(nextButton->isMouseButtonDown())
{
if(currentPosition > currentSong.duration - 20)
{
stopTimer();
nextClicked();
}

    // Forward the play by twenty seconds
}
else if(backButton->isMouseButtonDown())
{
    if(currentPosition < 20)
    {
        stopTimer();
        backClicked();
    }
    // Rewind the play by twenty seconds
}

}[/code]

Or something else efficient way to do such thing ? Please let me know…

Hi acn, thanks for the reply but the rewind functionality is not really the problem here, I have that working. The problem is that the rewind is not directly triggered by a button or mouse press but rather by an ApplicationCommandManager. I don’t know how familiar you are with these classes but basically your ApplicationCommandManager has callbacks when certain commands are triggered and then from these callbacks I implement the functionality of the rewind, menu showing etc.

There are various ways to trigger a command but they may come from different sources e.g. Mac menu bar, key press or in-app button. If I don’t attach a button to the command I get separate callbacks for key down and up evens which is good. When I attach a button however I only get the key down events.

I think I’m going to have to create a Button subclass that responds to button down and up internal callbacks and calls ApplicationCommandManager::invoke with the button state as the isKeyDown member.

Hammm Yes dave you are right, I am not yet that much aware with ApplicationCommandManager classes, But soon I will be applying them to ScPlayer too, So one can use shortcut keys to mange the different things…

Whenever I will get with the things you are working, and find any solution near to the one, Will report to you, Thanks for response.