Open GUI on key press

I’m trying to learn how to use Unity without copying scripts, so far I’m just trying to make a Inventory screen show up on key press, and Iv’e been looking around through the forums to figure out how to bring up a GUI when a key is pressed, but their all written in Javascript, I decided C# would be better since I could use it with other engines. Anyways this is the script I came up with

using UnityEngine;
using System.Collections;

public class InventoryGUI : MonoBehaviour {
	
	private bool showInventory = false;
	private bool inventoryKey = Input.GetKeyDown(KeyCode.I);

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void OnGUI () {

		if(showInventory = false;)
		{
			GUI.Box(new Rect(80, 50, 400, 200), "Inventory");
		}
		else{

		while(inventoryKey)
		{
			GUI.Box(new Rect(80, 50, 400, 200), "Inventory");
		}
	
		}

	}

}

I got it to one point where it popped up on play but not when you press a key, I feel kind of stupid for not being able to figure this out. Am I going in the right direction with this?

private bool showInventory = false;

void OnGUI()
{
    if(GUI.Button(new Rect(10,10,150,40),"Inventory show: "+showInventory)
    {
        if(!showInventory) showInventory = true;
        else showInventory = false;
    }

    if(showInventory)
    {
        GUI.Box(new Rect(10,55,200,200),"Inventory");
    }
}

This is a button what I’m trying to do is set up a key press for the box to come up not a button

Replace line 5. with:

if(Input.GetKeyDown(KeyCode.I))

Iv’e tried this and the window doesn’t come up when I press the key

Ohhh. im still learning.
I though i saw someone say that if its OnGUI, try not to use

if( Input.GetKeyDown(...) )

since its best called from Update().
…instead in OnGUI use

if( Event.current.isKey  Event.current.keyCode == KeyCode.I )

ooh Nice, this works much better except it only shows up for a split second, I think I can fix that part myself

EDIT: actually, I dont know this function, I can’t get it to stay open and not close after letting go

EDIT: Okay I fixed it with if((Event.current.Equals(Event.KeyboardEvent ("I"))