Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

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

Asked by 7 years ago

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

2 answers

Log in to vote
1
Answered by
einsteinK 145
7 years ago

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

Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

(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

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 einsteinK 145 — 7y
0
Ah, thank you. TheHospitalDev 1134 — 7y

Answer this question