Keyboard Focus issue


#1

We are having problems with keyboard focus when a 3rd party hosted plugin’s GUI is focused. We have tried setting the Plugin editor requires keyboard focus to false and have tried to implement this independently with the following

PluginWindow::~PluginWindow()
{
    if (isActiveWindow()) {
        setWantsKeyboardFocus(false);
        DocumentWindow::setWantsKeyboardFocus(false);
        }
    }
}

and varied this to

PluginWindow::~PluginWindow()
{
    activePluginWindows.removeFirstMatchingValue (this);
    setWantsKeyboardFocus(false);
    DocumentWindow::setWantsKeyboardFocus(false);
    clearContentComponent();
    
}

We have also tried

PluginWindow::PluginWindow (Component* const uiComp,
                            AudioProcessor * owner_,
                            const bool isGeneric_)
: DocumentWindow (uiComp->getName(), Colours::lightblue,
                  DocumentWindow::minimiseButton | DocumentWindow::closeButton | DocumentWindow::setWantsKeyboardFocus(false);),

and tried adding

isGeneric (isGeneric_)
{
        uiComp->setWantsKeyboardFocus(false);
}

But none of these have worked, the focused window still steals keyboard focus, which is preventing Spacebar playback in the DAW whilst the 3rd party plugin GUI is focused.


#2

The plugin’s window is free to call OS functions directly to give itself focus, and as a host there’s not much you can do about it.

One solution is to always capture spacebar presses, and dispatch them to subcomponents are required.


#3

Hi Tom,

Please help us how to dispatch them to subcomponents?
Is there a way to send a space key to parent components?

Thanks


#4

Something like this:

class TestWindow : public DocumentWindow
{
public:
    TestWindow ()
        : DocumentWindow ("test", Colours::red, 0)
    {}

    bool keyPressed (const KeyPress& key) override
    {
        DBG ("Key pressed in window!");
        return false;
    }
};

class MainContentComponent : public Component,
                             public KeyListener
{
public:
    //==============================================================================
    MainContentComponent()
    {
        setSize (600, 400);

        testWindow.setVisible (true);

        testWindow.addKeyListener (this);
    }

    ~MainContentComponent() {}

    void paint (Graphics& g) override {}

    void resized() override {}

    bool keyPressed (const KeyPress& key, Component* originatingComponent) override
    {
        DBG ("Caught key pressed!");
        return false;
    }

private:
    //==============================================================================
    TestWindow testWindow;

    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainContentComponent)
};

The return value of keyPressed indicates if you are going to consume the key press there or pass it along to the next component.


#5

Thanks for your answer.
I am trying your proposal now. and keep you updated.
Additional question:
When i press space bar on the main plugin window, i dont see the plugin handle the key pressed handler.
I just need to play track on DAWs.
Is there a way to do that ?


#6

Thanks,

I can hook the key from the document window.
But i can’t send it to daw to play the track.

I tried :slight_smile:
Return false on keypress event. But no result.

I need to send space key i hook above and send it to daw.

Now i dont know how to send space key to Daw.
Please give me more idea
thanks.


#7

Perhaps I misunderstood your use case.

If your application is a plug-in host then the above approach may work. If, however, you are trying to send a spacebar press to an external host from inside a plug-in GUI then I don’t know what will work; it’s the host’s responsibility to capture key presses it might be interested in.


#8

Thanks man.

I updated the information on attached image.

Jules can help me (hi hi hi hi i hope that).

Thanks all guy


#9

Tom already looked into this, and like he says, it’s not something we consider to be working incorrectly. Hosts generally use some hacky tricks to spy on keypresses that happen inside your plugin window, but if you start creating your own separate windows, you can’t expect the host to pay any attention to them.

All I can suggest would be that you catch spacebar presses yourself in your floating window, and then write your own win32 code to inject space key events into your plugin’s HWND, so that host may spot them.


#10

Yeah,

I considered your solution.
I am still looking for easier way to do that.

Keep this question open, if noone can answer this question. I ll try your proposal.
Thanks Jules,


#11

I fixed that with easy way.
Thanks


#12

Hi hungj,
May I ask you what is the easy way you found ?
Thanks