How to handle 'Ctrl+key' without the host registering this keycombination?

Hello,

What I want to do is use some standard key-combinations to change the behavior of a component in my plugin. (ctrl+A = select all, ctrl+Z = undo, etc). However the host (I use Ableton) also registers these combinations, so I also undo the latest changes made in Ableton (which I don’t want). I can’t figure out how to set that the keypresscombination is handled by the plugin. If I don’t use the ctrl, it works fine (checking if only letter Z is pressed works fine, it doesnt get sent to the host)

In my program I use the ‘bool keyPressed(Keypress key) override’ function to check for keyboard inputs. In the function I do this:

if (key.getKeyCode() == ‘A’ && && key.getModifiers().isCtrlDown()) {
//Do something
return true;
}

I know about the modifierKeysChanged function but that is a void, so I can’t return that the controlpress is handled.

In my constructor I did: setWantsKeyboardFocus(true);
And when the component was painted I grabbed the focus of the keyboard;

I’ve searched a lot and found some related topics to this but didn’t found a good answer.
Thanks in advance!
Ambroos

As of now, there is no way to achieve this in a way that works across all hosts and plugin formats.
The best you can do is requiring and acquiring keyboard focus (like all editable text labels do out of the box). If you’re using VST3 and Reaper, you’re out of luck: Reaper even consumes the space key while a text editor has focus - unless you use an obscure Reaper-specific function that redirects all keyboard input to the plugin, in Reapers UI.
I’d recommend getting a broader picture of this topic, using various host/platform/pluginformat combinations. Simply put an editable label somewhere and observe the behavior of space, enter, ctrl-a (select all text), ctrl-z (undo text edit) and so on. The host/platform/pluginformat combinations where this works you can also make to work for the “global” key commands you envision, by using regular JUCE API (requesting/acquiring kbd focus).
Also consider that this can be incredibly confusing for users. In many cases, the expectation is that keyboard commands are passed through to the host, for playhead control and similar things you do while operating a plugin UI with the mouse. The temporary exception being things like comboboxes, popup menus, and aforementioned text editors. If a plugin does not follow this convention, it messes with the users motor memory and workflow.

Anecdotal example: I still have to consciously remember that NI Maschine “steals” some global hotkeys that I use for controlling Cubase, and I’ve accidentally recorded patterns within Maschine that I had to delete afterwards many times. :wink:

2 Likes

Thanks for the aswer!

I’ll always tested with Ableton and assumed everything will work fine in other DAWs too. Don’t have the budget to buy too much daws but I’ll look into downloading some demo’s if thats possible. It sucks that DAWs not share how they handle things, would be a huge timesaver.

And for the confusing part: I generally agree with you but I have a vst that lets the user edit Midi inside it (as in the attachement shown). I want the behavior of editing these notes be the same as editing midi in ableton, but that won’t be possible now.

Another option I thought would be that the user can select themselves in the settings which key to use for what and set some default keys for the start. However I don’t know for the moment how to save that data so that the personalised keydata will be used when you create a new instance of your plugin in your DAW. But I’ll look into it.