How to detect keyboard presses when focused on a TextBox

Exactly what the title says, I need to detect keyboard presses for TextBoxes. This is different when detected when text changes, because it doesn’t give me exactly what the user typed (for example, Ctrl+V pastes text, so the text change is whatever I pasted, but keyboard press detection should give me Ctrl and V). I already tried using TextBox.InputBegan, TextBox.InputChanged, and TextBox.InputEnded, but those don’t fire when I press my keyboard. UserInputService just doesn’t fire when I’m focusing on a TextBox. Is there a solution?

3 Likes

UserInputService just doesn’t fire when I’m focusing on a TextBox

That’s actually not true. UserInputService does fire even if you are focusing on a TextBox. What developers do to prevent this is run the check:

if not UIS:GetFocusedTextBox() then -- UIS stands for UserInputService

end
1 Like

You can also use either:

TextBox.Focused:Connect(function()
    -- do code
end)
or
if (TextBox:IsFocused()) then
    -- do code
end
2 Likes

I forgot to mention that this is for a plugin (I’m using widgets), so this just doesn’t work, I even tested this myself.

You can just get the text from the textbox whenever the person stops typing the the textbox.

Try this but i dont sure about performance because it very sensitive when you try to do something to textbox (I type my keyboard and it call a function three time I dont know what another two changed with a text of textbox)

local TextBox = script.Parent
TextBox.Changed:Connect(function()
	-- Code
end)