Implementing a virtual keyboard component

I'm putting together a virtual keypad component for numeric text entry in my mobile app. This is so I have full control over it, I want to move away from OS-provided soft keyboards. 

I have a simple component that contains the keypad buttons. This is generating characters which are sent to an editor component. The editor component has 3 editable Labels. However, if the user clicks on the keypad button, the editor component label loses focus and the label's TextEditor component disappears. 

I've set the editor component's labels to ```setWantsKeyboardFocus (true)```, and for each button in the keypad component I've set both ```setMouseClickGrabsKeyboardFocus (false)``` and ```setWantsKeyboardFocus (false)```

I'm using a callback function thats called whenever a keypad button is pressed. Its able to see that the focused component is a label, but can't find its TextEditor, I'm guessing because its already disappeared at that point.

void MyEditor::keyInput(char key)
    if (Component* focusComp = getCurrentlyFocusedComponent())
        if (focusComp == label1 || focusComp == label2 || focusComp == label3)
            // Reaches here
            TextEditor* textEditor = dynamic_cast<Label*> (focusComp)->getCurrentTextEditor();
            if (textEditor != nullptr)
                textEditor->insertTextAtCaret (String (key)); // <-- does not reach here

Is there a way to keep the TextEditor alive while clcking other buttons? 

I've decided to not to make the Label editable via TextEditor and use the keypad only, like a calculator app. This also solves justification issues with Label / TextEditor switching. 


Did you ever finish something here? Would be of interest to see what you came up with.


No, ended up using native iOS/Android soft keyboard. Might still do this but if I do I won’t build it with JUCE - I’m doing most of my mobile app UI with native APIs/React Native now.

1 Like

Cool! Thanks. Was looking at a few existing virtual keyboards that can be embedded as Gtk widgets but none seem to have the possibility of styling to your own look and feel.