Disable Hold Key Down

what im trying to do is I created a script to be able to edit a string. However I want to be able to only allow one character to display per key press so that the player cannot hold down the key and get multiple characters Ex: aaaaa bbbbbbb cccccc.

I am aware of Input.GetKeyDown and Input.GetKeyUp but dont know where to go from there

Please Help!

You need to create a project input tag and put it in between the "" below.

function Update(){
if (Input.GetKeyDown("ProjectInputKey")){ 

If I understand correctly, you're dealing with the HW or OS 'auto repeat' function. I had a similar problem (I think). What I did was use and array (or hash table) to keep track of when keys go down and up, and ignore them if already down. I would think you'd have to avoid using TextArea or TextField if you can't trap characters there (I'm not sure you can't). But you could 'roll your own' by using Input.GetKeyDown/Up and and array or hashtable, and a Label.


I guess you want something like that:

function Update ()
    if (Input.anyKeyDown && Input.inputString != "")
        // Debug.Log(Input.inputString);

inputString contains the keys that have been pressed in this frame (most of time it's just one single character). anyKeyDown is true only for one frame when any button is pressed but it's not repeated.

I'm not sure why someone need that behaviour but for TextFields you can use Event.current.Use() to intercept the key messages. Just make sure you do the interception before your textfield inside OnGUI.