Handling Ctrl-Space

Hey there - I’m trying to handle Ctrl-Space in a code editor component to trigger an auto-complete popup. I’m on Mac.

I’m overriding bool keyPressed(const KeyPress& key) override in my custom code editor component but this never gets called on Ctrl-Space. It seems that NSViewComponentPeer::handleKeyEvent does not forward the event because the native characters of the event is an empty string.

 bool handleKeyEvent (NSEvent* ev, bool isKeyDown)
    {
        auto unicode = nsStringToJuce ([ev characters]);
        auto keyCode = getKeyCodeFromEvent (ev);
[...]
        if (keyCode != 0 || unicode.isNotEmpty())
        {
            if (isKeyDown)
            {
                bool used = false;
                // never enters loop here ...
                for (auto u = unicode.getCharPointer(); ! u.isEmpty();)
                {

I’m obviously missing something here …

Can anybody help?

Thanks a lot,
Daniel

1 Like

[Bump]

Anybody can help? I’m actually pretty sure now that this is a bug in JUCE.
I created a minimal case with just a simple component that overrides

bool MainComponent::keyPressed(const KeyPress& key)
I get all key presses. Including Option-Space but not Ctrl-Space.

For some funky reason [NSEvent characters]
Option-Space: wchar_t L'\x01' \x01\0\0\0
Ctrl-Space: '\0'

When I’m patching NSViewComponentPeer like this (obviously super ugly) I get Ctrl-Space events:

    bool handleKeyEvent (NSEvent* ev, bool isKeyDown)
    {
        auto keyCode = getKeyCodeFromEvent (ev);
        auto unicode = keyCode != 32
            ? nsStringToJuce ([ev characters])
            : " ";