Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a way to start typing in a text box by detecting a key press?

An example would be the default chat system in-game, where pressing "/" automatically begins typing.

2 answers

✓ Accepted answer

There is a method TextBox:CaptureFocus() to make a user start typing in that textbox.

(Thanks to einsteinK for saying about the Capture Focus method!)

You are talking about the wonderful UserInputService!

For an example of this,

local service = game:GetService("UserInputService") -- The service required to detect UserInput
local gui = script.Parent --My gui

service.InputBegan:connect(function(keyPressed,gameProcessedEvent) --Connect the function
    if gameProcessedEvent then 
    	return 	end
  	if keyPressed.KeyCode == Enum.KeyCode.Slash then --If "/" then do...
    	gui.TextBox:CaptureFocus() --To start typing.
   	end
end)

Hope I helped!

THIS MUST BE A LOCAL SCRIPT

2 comments

0

also add "if gameProcessedEvent then return end" otherwise it'll capture the textbox every time you press slash, even while already entering text in another textbox

0

Ah, thank you.

This discussion is preserved as it was. New answers, comments, and votes are closed.