Mobile fails to :CaptureFocus for some reason?

Recently I’ve been working on an open sourced resource known as SocialChat. However, my resource lacks mobile support, in which I have tried to implement within the past month. Sadly, I have run into the issue of :CaptureFocus() failing to work as intended. I am not sure why this happens but I can’t seem to fix the issue regardless of what I do.

I made some code to ensure that it wasn’t just my something from my own behalf but my printing seems to work as intended.

DisplayLabel.InputBegan:Connect(function(Input)
        print("DISPLAY LABEL INPUT?");

        if ((Input.UserInputType == Enum.UserInputType.Touch) or (Input.UserInputType == Enum.UserInputType.MouseButton1)) then
            ChatBox.CursorPosition = LastSavedCursorPosition
            SetTextBoxVisible(false);
            SetChatHidden(false);

            print("TOUCH FOCUS");
            ChatBox:CaptureFocus();
        else
            warn("(FAILED INPUT) Type:", Input.UserInputType);
        end
    end);

Footage of said occurance:

Looking at your code and video I can’t really tell what it is that you’re trying to have happen before you attempt to call CaptureFocus.

The message didn’t get sent. Maybe the “ENTER” action wasn’t recorded? Even Roblox’s chat does that sometimes…

I intentionally clicked off of the keyboard because the TextBox fails to CaptureFocus after that.

The functions prior to the :CaptureFocus event are synchronous callbacks which do not yield the code and only affect the chat visually. My issue is that my mobile keyboard seems to never come back after I lose focus on the TextBox.

So you’re saying when you tap out of chat it’s supposed to focus it again? Sorry for asking stupid questions. I just woke up and am in the airport, and on top of that I don’t know what your end goal is here and what exactly it isn’t doing correctly.

No worries! I apologize for being unclear. :sweat_smile:

Basically what I’m showing in the video is that I am able to successfully send messages with my Chat system using :CaptureFocus. However, if the TextBox is actively already Focused and I do something to lose focus other than pressing the Return button on my mobile keyboard, CaptureFocus seems to never successfully bring up my keyboard again.

What are you doing in the video to cause the .InputBegan event to be fired again after that 3rd message and cause it to gain focus again?

I clicked on the ChatBox which is what I was previously doing for the rest of my previous inputs. I am not sure but I believe this may possibly be an Engine Bug.

Ah, I see what you’re saying now. One thing you could try it releasing the focus and then capture it again. (This is just a fix for the temporary)

It does sound like something on the Roblox side for the keyboard not coming back up while the cursor is already there.

1 Like

I tried this but it still seems to fail. It appears as though .Focused doesn’t fire when the bug occurs which signifies that :CaptureFocus does indeed fail to work as intended.

1 Like

Bug report time! Stupid 30 limit

Yield for a frame before calling TextBox:CaptureFocus. InputBegan is likely firing before the textbox’s focus is lost.

task.defer(TextBox.CaptureFocus, TextBox)
1 Like

This doesn’t work unfortunately. Im not really sure how to flag this as a Roblox Engine bug either.

Yielding has worked for me in a similar situation before. I’m unable to watch the video provided, can you describe the issue(s) being displayed?

Sure thing!

The video shows that I am able to use :CaptureFocus on Mobile to bring up the Keyboard for mobile client’s to type their own chat inputs into. This works perfectly fine whenever you click the TextBox and send your message. However, whenever you input text into the text box and lose focus on said TextBox, Mobile users are no longer able to pull up their mobile keyboards during a :CaptureFocus event regardless of the event actually being fired.

Heres a few details that may help with comprehension:

  • CaptureFocus does not fire BUT the code that fires said event does run. I have verified this through my output with the usage of prints and I am confident that there is nothing yielding the event from being fired.
  • This bug only occurs whenever a mobile client fires the CaptureFocus event, but then proceeds to fire the FocusLost event; thus preventing the mobile client from ever firing CaptureFocus ever again.