Simple GameObject Hide/Unhide with bool!!!

Hello,

In my script, a bool turns true whenever a Key is held down in the update, and turns false when it’s not held down. (this works)

void Update()
{
myBool = Input.GetKey(KeyCode.G);
}

However, when i want a GameObject to be SetActive according to that bool, it won’t work and the bool stays true, even when the key is let go. This is what i put in for turning on the GO in the script

GO.SetActive(!Input.GetKey(G));

Why is this? Can someone help with the GO being SetActive when the key is being held down and vice-versa? Thank you!!

var keyPressed = false;

// [...]

if (Input.GetKeyDown(KeyCode.G)) keyPressed = true;
if (Input.GetKeyUp(KeyCode.G)) keyPressed = false;

// [...]

GO.SetActive(keypressed); // Shows only while the button is pressed.