In Bitwig keyPressed is called twice per character [solved]

[solved: just go to the latest JUCE develop]

Unless it’s a bug in my own code ofc. But I was told there were some recent hacks around other keyboard focus aspects so I guess it could be a JUCE bug. Anyway if anyone runs into the same issue, here’s my hack around the hack:

In the class that should have a keyPressed method I have an object of this:

struct TimeConstrainer
{
    static constexpr juce::uint32 IntervalMs = 10;

    TimeConstrainer() :
        timeStart(0)
    {
    }

    bool isReady() noexcept
	{
        if (timeStart == 0)
        {
            timeStart = juce::Time::getMillisecondCounter();
            return true;
        }
        const auto newTime = juce::Time::getMillisecondCounter() - timeStart;
        if (newTime < IntervalMs)
            return false;
        timeStart = juce::Time::getMillisecondCounter();
        return true;
	}

protected:
    juce::uint32 timeStart;
};

so everytime in keyPressed I call isReady and if it’s not then I immediatly return true to tell Bitwig, that this character has already been consumed.

1 Like

I’m seeing a similar thing specifically in Bitwig, where pasting from clipboard with ctrl+v into a juce::TextEditor pastes the content from the clipboard into the editor twice, doesn’t happen in other hosts, and doesn’t happen if I paste using the context menu, figured it may be related?

1 Like

IIRC a similar behavior was reported also about Pro Tools, I don’t know if it was ever resolved and on which side (meaning whether Pro Tools was fixed to behave correctly, or JUCE worked around it specifically for Pro Tools)

Sure you’re not getting two messages - one for keyDown and one for keyUp - and are forgetting to check the state somewhere? Its quite useful to get a separate message for a key UP event … for the case where QWERTY is being used as a Piano keyboard, for example …

1 Like

We are getting the same problem in FL Studio. Ctrl-V into a text editor pastes the text twice.
Studio One is fine though.

EDIT: In our case it seems to be a bug introduced in JUCE 7.0.6. Because when I build using JUCE 7.0.5 Ctrl-V is fine. But since JUCE 7.0.6 we get the text pasted twice in FL Studio.

if this is what’s going on i could remove my hack in favor of a little if statement that excludes one of these. looking forward to try that

When filing bug reports, please include instructions to reproduce the problem so that we can determine whether there is really a defect. From the description, it’s not clear under what circumstances you’re seeing duplicate keypresses.

We recently pushed a fix for an issue with a similar description. Please try updating and check whether the problem is resolved. If it is not resolved, please provide instructions and example code to reproduce the problem.

1 Like

yep, the most current commit of JUCE develop solved this