Mobile Enter Button Pressed Event

  1. What do you want to achieve? I want to run code for my custom chat when a mobile (and all other platforms) player has pressed the Return (enter) button on their virtual keyboard before sending the message.

  2. What is the issue? Neither Enum.UserInputType.Keyboard or Enum.UserInputType.TextInput seem to respond to this button press. I am using Bluestacks for mobile emulation, and the desktop player for an easier way to see the server prints.

  3. What solutions have you tried so far? I’ve looked for solutions, but all solutions for my searches say “Use Mobile Buttons” (ContextActionService) which isn’t what I’m looking for.

Client Script
UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.Return then
			testEvent:FireServer()
		end
	end
end)
Server Script
testEvent.OnServerEvent:Connect(function(player)
	print(player.Name)
end)
1 Like

Enum.KeyCode.Return is the input which should correspond to a mobile user pressing the enter/return key on their virtual keyboard, are you working with a TextBox instance?

Yes, I was working with a TextBox. Have you confirmed this yourself?

Bump, still having this issue, have retested with the normal desktop client and it works flawlessly. For more context, I’m clicking this button on the Android virtual keyboard when submitting a message.
image

Edit: I’ve just tested this on an iPad, and am getting the same results: printing for my desktop instance, nothing for mobile. I’ve searched for this again and have seen no other issues.

You can try using the TextBox.FocusLost Event like this:

TextBox.FocusLost:Connect(function(enterPressed)
   if enterPressed then
      
   end
end)

if this does not work, you can check what type of input caused focus loss and adjust your code for it like this:

TextBox.FocusLost:Connect(function(_, input)
   print(input.UserInputType, input.KeyCode)
end)
2 Likes

This is dumb that Roblox’s Enter Pressed Event doesn’t fire on mobile, but the top solution does work well. For anyone who’s curious, here’s what my code looks like:

Client Script
UIS.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.KeypadEnter or input.KeyCode == Enum.KeyCode.Return then
			module.AttemptChatMessageSend(chatTextBox)
		end
	end
end)

chatTextBox.FocusLost:Connect(function(enterPressed)
	if enterPressed then
		module.AttemptChatMessageSend(chatTextBox)
	end
end)
Module Script
module.AttemptChatMessageSend = function(chatTextBox)
	local message = chatTextBox.Text
	print(message)
	if message ~= "" then
		local messageSent = chatFunction:InvokeServer(message)
		testEvent:FireServer()

		if messageSent == true then
			chatTextBox.Text = ""
		end
	end
end
module.Chat = function(bubbleObject,message,color)
	Chat:Chat(bubbleObject,message,color)
end
Server Script
chatFunction.OnServerInvoke = function(player,message)
	local textFiltered = module.CompareStrings(message,module.FilterText(message,player.UserId,Enum.TextFilterContext.PublicChat):GetNonChatStringForBroadcastAsync())
	
	if textFiltered == false then
		module.Chat(player.Character:WaitForChild("Head"),message)
		return true
	else
		return false
	end
	
end
1 Like