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.
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.
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)
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?
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.
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.
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