Forwarding key events of desktop windows to host


#1

In a plugin, I have a separate window created on the desktop (via addToDesktop). While this works fine in general, the desktop window doesn’t forward unused key events to the host so for example pressing space to start/stop playback won’t work.

I had a look on how to forward unused events but wasn’t very successful. At the moment I’m not even sure whether this is possible at all.

I’d be grateful for any hints on how to accomplish that on macOS and/or Windows. It’d even be good to know if this isn’t possible in the first place so I can focus on other stuff again.


#2

It seems on macOS, only the space key isn’t forwarded to the host. Other keys seem to work at least in Logic and Reaper.

I was able to accomplish forwarding the space key by asynchronously (e.g. in a Timer) transfering keyboard focus to the plugin window (myPluginEditor->grabKeyboardFocus()), posting a keyboard event and returning focus to the desktop window (myDestopWindow->getKeyboardFocus()). While it works (and probably will also work on Windows) this certainly isn’t very elegant.

So, I’d be still happy for any further input.


#3

Unfortunately hosts use a variety of hacks to obtain key presses from plug-ins, so it’s difficult to know what will work.

One approach that would be more elegant, but also more effort, would be to write some native code for each platform that creates space key events in the plug-in window. We’ve had people asking about this on the forum before, so perhaps this is functionality we could add to JUCE in the future.


#4

That’s more or less what I’m doing now. I created a class that starts a Timer where in three steps keyboard focus is changed, a key event is sent and then key focus is returned. The key event code is separate for Windows and macOS. It also only works for the space key as I only found system calls that take virtual key codes.

Since the desktop window belongs to the host process, sending a key event to the host will get back to the desktop window as long as it holds keyboard focus.

Strangely, other keys on OS X only worked in a testing implementation where the desktop window didn’t do much. After implementing it in the actual plugin only space works.

Of course, it’d be great if this were implemented in JUCE.