VR Reality Bug UserInputService.TextBoxFocused

VR (Virtual Reality) Bug

Issue related to ROBLOX-VR


Recently, I’ve been working on a game with my buddies while one of them had a problem while constructing a Gui-based Qwerty keyboard for the VR Players.

We discovered in our vision that UserInputService.TextBoxFocused and UserInputService.TextBoxFocusReleased are not compatible with Virtual Reality mode.

StarterPlayer.StarterPlayerScripts:

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local VRService = game:GetService("VRService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")

if (not VRService.VREnabled) then
	return
end
print("hi!")

local VRTextboxFocus = require(ReplicatedStorage.VRTextboxFocus)

local localPlayer = Players.LocalPlayer
local camera = workspace.CurrentCamera
local connections = {}

local GuiPart = Instance.new("Part")
GuiPart.Name = "GuiPart"
GuiPart.Anchored = true
GuiPart.CanCollide = false
GuiPart.Transparency = 1
GuiPart.Parent = workspace

local surfaceGui = Instance.new("SurfaceGui")
surfaceGui.Enabled = false
surfaceGui.Adornee = GuiPart
surfaceGui.Parent = localPlayer.PlayerGui

local vrKeyboard = ReplicatedStorage.VRKeyboardContainer:Clone()
for _, descendant: Instance in ipairs(vrKeyboard:GetDescendants()) do
	if descendant:IsA("GuiBase") then
		descendant.Size /= 4
	end
end
vrKeyboard.Parent = surfaceGui

local s1 = vrKeyboard["1"]
local s2 = vrKeyboard["2"]
local s3 = vrKeyboard["3"]
local s4 = vrKeyboard["4"]

function registerButton(textbox: TextBox, button: TextButton)
	table.insert(connections, button.Activated:Connect(function()
		local text = textbox.Text
		if button.Name == "Delete" then
			textbox.Text = text:sub(1, #text - 1)
			return
		end
		if button.Name == "Enter" then
			if textbox.MultiLine then
				textbox.Text ..= "\n"
			else
				textbox:ReleaseFocus(true)
			end
			return
		end
		
		textbox.Text ..= button.Text
	end))
end

VRTextboxFocus.TextBoxFocused:Connect(function(textbox)
	
	print("focused!")
	textbox:CaptureFocus()
	surfaceGui.Enabled = true
	
	for _, child in ipairs(vrKeyboard:GetDescendants()) do
		if child:IsA("TextButton") then
			registerButton(textbox, child)
		end
	end
end)

VRTextboxFocus.TextBoxFocusReleased:Connect(function(textbox)
	print("unfocused!")
	textbox:ReleaseFocus(true)
	surfaceGui.Enabled = false
	
	for _, connection: RBXScriptConnection in ipairs(connections) do
		connection:Disconnect()
	end
end)

VRService.UserCFrameChanged:Connect(function(_type, value)
	if _type == Enum.UserCFrame.Head then
		GuiPart.CFrame = camera:GetRenderCFrame():ToWorldSpace(CFrame.new(0, 0, 2))
	end
end)
2 Likes

We’ve filed a ticket to our internal database, and we’ll follow up when we have an update.

Thanks for the report!

5 Likes

Any progress yet? I was just wondering. :thinking:

1 Like