No matching constructor for initialization of 'juce::KeyPress'

Hi, I’d like to return a KeyPress by a func but compiler says:
No matching constructor for initialization of ‘juce::KeyPress’

Here’s the code:

KeyPress getRightScrollKeys() { return KeyPress(KeyPress::rightKey, ModifierKeys::altModifier); }

why? I follow the docs in source of KeyPress file:

/** Creates a KeyPress for a key and some modifiers.

    CTRL+C would be: KeyPress ('c', ModifierKeys::ctrlModifier)
    SHIFT+Escape would be: KeyPress (KeyPress::escapeKey, ModifierKeys::shiftModifier)

    @param keyCode      a code that represents the key - this value must be
                        one of special constants listed in this class, or an
                        8-bit character code such as a letter (case is ignored),
                        digit or a simple key like "," or ".". Note that this
                        isn't the same as the textCharacter parameter, so for example
                        a keyCode of 'a' and a shift-key modifier should have a
                        textCharacter value of 'A'.
    @param modifiers    the modifiers to associate with the keystroke
    @param textCharacter    the character that would be printed if someone typed
                        this keypress into a text editor. This value may be
                        null if the keypress is a non-printing character
    @see getKeyCode, isKeyCode, getModifiers

That function requires a third parameter. It is not optional. Those examples are incorrect. You can just pass 0 as the third parameter, since that keypress is not a printable character.

1 Like

I’ll get that documentation updated, thanks!


Thank you all!