How to get constant rotation from tapping a button

I want to be able to press a button and have my gameObject be constantly rotating on the y-axis. When I press the same button again, I want my gameObject to stop rotating. Here’s is what I have so far.

public int speed;
void Update(){
	if (Input.GetKey (KeyCode.W)) {	
          transform.Rotate (Vector3.up * Time.deltaTime * speed );
        }
}

When I press W it will start to rotate but stop with I let go of the button.

This will work:

public int speed;
bool shouldRotate = false;

void Update(){
    if (Input.GetKeyDown(KeyCode.W))
    {    
        shouldRotate = !shouldRotate;
    }

    if(shouldRotate)
    {
          transform.Rotate (Vector3.up * Time.deltaTime * speed );
    }
}