GetKeyUp fires twice?!?

I have a script listening if the user presses a key.

void OnGUI()
{
    if (Input.GetKeyUp(KeyCode.C))
    {
        print("c pressed");
    }
}

The problem is that 'c pressed' is printed twice when the user releases the "c" key. Is this a bug or do I do something wrong here?

OnGUI is called multiple times a frame - a minimum of twice (except on iphone where you can disable the layout event)

Use something like this if you need to use OnGUI:

if (Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.C)
{
    print("c pressed");
}

Since you’re saying that it even gets called twice inside of Update, the problem clearly seems to be that you have two objects in your scene running this same script at the same time. I’m not sure how that would have happened, but it seems the most likely culprit.

Personally, I prefer to move my input-checking to the Update() function, like so (C# ahead):

bool quitMenu = false;

void Update () {
    CheckKeys();
}
void CheckKeys() {
    if (Input.GetKeyUp(KeyCode.Escape)) {
        quitMenu = !quitMenu;
    }
}

By setting a boolean variable, I can then display a Menu in OnGUI() based on quitMenu.