activate object on key press only, otherwise always deactivated!

Hi,

I need to create a simple code for an object to activate on a ‘key’ press only, otherwise always it should be deactivated.
The problem I have is that it doesn’t functions as I wanted, instead it toggles, pressing key results into activation on and another press make the object deactivate. All I need is just one press key activate object and deactivate when I lift the key up. Also tried GetKeyDown() and GetKeyUp() but it ends up toggling it.
Here’s my non-working code:

void Update () {

        animObject.SetActive(false);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            animObject.SetActive(true);
            Application.CaptureScreenshot("screeshot.png");
        }
    }    

My purpose : Is to take a screenshot of the object while key is pressed and take a screenshot of it, and then deactivate object such that it doesn’t seen on a visible scale, The object must be invisible (deactivated) all the time.
Thanks

i know you said you tried this however is this the code you used? it could have been toggling because in the script you posted you are setting animObject.SetActive(false) every frame.

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
animObject.SetActive(true);
Application.CaptureScreenshot("screeshot.png");
        }

        if (Input.GetKeyUp(KeyCode.Space))
        {
animObject.SetActive(false);
        }
    }

Like this?

    private void Update () 
    {
         if (Input.GetKeyDown(KeyCode.Space))
        {
            animObject.SetActive(true);
            StartCoroutine(Capture());
        }
    }

    IEnumerator Capture()
    {
        Application.CaptureScreenshot("screenshot.png");
        yield return new WaitForEndOfFrame();        
        animObject.SetActive(false);
    }

Edit: I updated my answer according to your comment.