I need to make that every time I write something in the textbox and then press the “Enter” key this text is displayed in the textlabel, how is this possible?
script:
UserInputService = game:GetService("UserInputService")
local aKeyPressed = false
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.KeypadEnter then
print ("Pressed enter key")
aKeyPressed = true
while aKeyPressed == true do
wait()
-- do something here
end
end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.KeypadEnter then
print ("End presed enter key")
aKeyPressed = false
end
end)
The FocusLost event is a nifty event, especially when you want to detect the text being outputted back
Its parameter can be useful in this current situation, since EnterPressed will detect if the Text entered upon removal has been pressed by the Enter key or not
I suppose you could reference it like this, as a LocalScript inside the TextBox object
local TextBox = script.Parent
local TextLabel = script.Parent.TextLabel
TextBox.FocusLost:Connect(function(PressedEnter)
local CurrentText = TextBox.Text
if PressedEnter then
TextLabel.Text = CurrentText
end
end)
Looking at the API, I suppose you can think of Focused as like the opposite of FocusLost lol
Focused fires as soon as you hover your mouse on the TextBox, while FocusLost fires as soon as your mouse leaves the TextBox (Or given specific parameters you can detect if the FocusLost was detected by an EnterPressed parameter)