How do you detect if the cursor is visible within another window?

I’m trying to get my unity game to run in the background while I play other games.
I’ve got keyboard/mouse input working in the background thanks to ReWired.

But now I’m trying to figure out how to get my unity game to check if the cursor is visible or not.

So in Fortnite for instance, when you’re in the menu screen, the cursor is visible.
But when you get into playing the game (third-person shooter), the cursor disappears.

So I’m trying to get my background Unity game to detect when the cursor is visible and when it’s not visible within another game.
Does that make sense?

I tried:

If (Cursor.visible == true) 
      //Do this 
Else if (Cursor.visible == false) 
      //Do this 

But that didn’t work.
Only the true statement worked, as it thought the cursor was always visible, even though it wasn’t.

I read somewhere that Cursor.visible only works within the Unity window and not anywhere else.

So what would I need to do to get this working?
Any insight would be appreciated. Thanks!

(P.S. I only need this to work on Windows)

You’ll likely have to call Windows’ native cursor functions (specifically GetCursorInfo : GetCursorInfo function (winuser.h) - Win32 apps | Microsoft Learn ), quite possibly with a C++ DLL.

So I dove deep and figured out what I believe should work. But for some reason, update always returns the “else if” value right when I start up the game, even though the cursor is clearly visible. Any idea what I’m doing wrong?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using System;
 using System.Runtime.InteropServices;
 public class DebuggingInfo : MonoBehaviour

     public Int32 cbSize;
     public Int32 flags;
     public IntPtr hCursor;       

 [DllImport("user32.dll")] static extern bool GetCursorInfo(out CURSORINFO pci);
 const Int32 CURSOR_SHOWING = 0x00000001;

 void Update()
     CURSORINFO pci;
     pci.flags = System.Runtime.InteropServices.Marshal.SizeOf(typeof(CURSORINFO));

     if (pci.flags == CURSOR_SHOWING)
         Debug.Log("Cursor is visible");

     else if (pci.flags != CURSOR_SHOWING)
         Debug.Log("Cursor is NOT visible");