How To To Pause Section Of Script After Key Is Pressed Or Game Loses Focus

I am making a script to move the cursor to the center of the window and i need so that the cursor will stop moving when a key is pressed or the game loses focus. I also need to have the code continue once the game is clicked again.

Here Is My Code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class cursorLock : MonoBehaviour
{
    public static float WinH = Screen.height; // Height Of Current Window
    public static float WinW = Screen.width; // Width Of Current Window
    public Vector2 WinCenter = new Vector2 (WinH / 2, WinW / 2); // Center Of Current Window
    public void SetLocalCursorPos() // Moves Cursor
    {
        CursorControl.SetLocalCursorPos(WinCenter); //Cursor Position to Center
    }
    void FixedUpdate() 
    {
        SetLocalCursorPos(); // So Cursor Constantly Moves To Center
    }
}

@Phantom07 Unity - Scripting API: CursorLockMode

If (inMenu == true)
{
Cursor.lockState = CursorLockMode.None;
}
else
{
Cursor.lockState = CursorLockMode.Locked.
}