How to check if text has been pasted into a textbox?

I’m looking for something like: TextBox.TextPasted:Connect()

There is no specific way, but you could check through a changed event and check if the length difference is greater than one.

local prevtext = ""
local textbox = --textbox

textbox:GetPropertyChangedSignal("Text"):Connect(function()
    if string.len(textbox.Text) - string.len(prevtext) > 1 then
        print("pasted")
    end
    
    prevtext = textbox.Text
end)

There is also a way of checking if the user is pressing ctrl+v simultaneously, but it would require many more checks and I figured this way was better.

1 Like
local Game = game
local UserInputService = Game:GetService("UserInputService")
local Script = script
local TextBox = Script.Parent

local function OnInputBegan(InputObject)
	if not (TextBox:IsFocused()) then return end
	if InputObject.KeyCode.Name == "V" and (UserInputService:IsKeyDown("LeftControl") or UserInputService:IsKeyDown("RightControl")) then
		print("User pasted the contents of their clipboard.")
	end
end

UserInputService.InputBegan:Connect(OnInputBegan)

You can also use ‘C’ to detect when text is copied to the clipboard (inside of a ‘TextBox’ instance).

I know this was a while ago, but this isn’t accurate.