Download

VirtualKeyboard : Sending Input to SEditableTextBox

Getting SEditableTextBox, and by extension SEditableText, to accept input pragmatically has been a challenge. More than it needs to be that’s for sure. Hopefully I’m doing something wrong and it actually is straightforward. In summary, I have a class that inherits from UEditableTextBox that adds a function SendKey, which is called from a Blueprint that has a virtual keyboard displayed:



.h
UCLASS()
class MYAPP_API UMyEditableTextBox : public UEditableTextBox
{
    GENERATED_BODY()

public:

    void SendKey(FKey Key);
};


.cpp
void UMyEditableTextBox::SendKey(FKey Key)
{
    if (MyEditableTextBlock.IsValid())
    {
        // Backspace
        if (Key == EKeys::BackSpace)
        {
            return;
        }
        else if (Key == EKeys::Left)
        {
            //FMoveCursor Args = FMoveCursor::Cardinal(ECursorMoveGranularity::Character, FIntPoint(0, -1), ECursorAction::MoveCursor);
            //EditableText->MoveCursor(Args);
            return;
        }
        else if (Key == EKeys::Right)
        {
            //FMoveCursor Args = FMoveCursor::Cardinal(ECursorMoveGranularity::Character, FIntPoint(0, 1), ECursorAction::MoveCursor);
            //EditableText->MoveCursor(Args);
            return;
        }
        else if (Key == EKeys::Tab)
        {
            return;
        }
        else if (Key == EKeys::Enter)
        {
            return;
        }

        if (!IsReadOnly)
        {
            FString c = Key.ToString();
            if (c.Equals(FString("SpaceBar")))
                c = " ";

            FModifierKeysState InModifierKeys;
            uint32 InUserIndex = 0;
            bool bInIsRepeat = false;

            FCharacterEvent InCharacterEvent(*(const TCHAR*)(*c), InModifierKeys, InUserIndex, bInIsRepeat);
            FSlateApplication::Get().ProcessKeyCharEvent(InCharacterEvent);
        }
    }
}


Unfortunately the control doesn’t behave as one would expect. For instance:

  1. When

IsCaretMovedWhenGainFocus = false;

any input directed to the control is always at the first position

  1. Likewise, when

IsCaretMovedWhenGainFocus = true;

input is always appended to the last position

Additionally, you may notice that I tried to directly manipulate the SEditableText control via FMoveCursor. This is remnants of another attempt I tried to pragmatically manipulate the EditableText control. This attempt required that I redo the existing SEditableTextBox class and allow for access to the member variable, which was straightforward. However, I encountered a linker error with the FMoveCursor class, something that I could not resolve.

  1. How do I resolve the FMoveCursor linker error?

Can anyone help with any of these? Does anyone have any suggestions or better ideas on how to implementation this?

Any help is appreciated.

I need to bump this.