# How can I block Copy/Paste from Input Fields in Unity?

I don't want the user to write a text by copying and then pasting the content to an Input Field, how can I do that?

• Mind if I ask why? – Tyyppi_77 Aug 27 '17 at 23:17
• One caution to be aware of here is that this may impact accessibility for some users who, for one reason or another, have difficulty typing text directly into your game's interface. – DMGregory Nov 8 '17 at 13:08

I haven't tested the following script, but I guess you can detect whether the paste keys are pressed when the value of the input changes.

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour
{
public UnityEngine.UI.InputField mainInputField;
private string inputValue;

public void Start()
{
inputValue = mainInputField.text;
}

// Invoked when the value of the text field changes.
public void OnInputValueChanged(string newValue)
{
if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && (Input.GetKey(KeyCode.V) || Input.GetKeyUp(KeyCode.V)))
{
Debug.LogError("Not allowed");
mainInputField.onValueChanged.RemoveListener(OnInputValueChanged);
mainInputField.text = inputValue;