-1

I want to center mouse cursor. Here how I do it.

enter image description here

But here is a problem - when I change active window with alt + tab, cursor still in the center all the time. Can I check somehow that game window is focusable?

Amazing User
  • 3,473
  • 10
  • 36
  • 75

1 Answers1

1

You can call IsForegroundWindow() on your LocalPlayer’s ViewportClient->Viewport.

Something like:

ULocalPlayer* LocPlayer = Cast<ULocalPlayer>(Player);
if (!LocPlayer->ViewportClient->Viewport || !LocPlayer->ViewportClient->Viewport->IsForegroundWindow())
{
    // viewport is either not present or not in the foreground.
}

…should work for you. Player lives within the PlayerController, so the above code will work if called from within a playerController, or can be called somewhere else by grabbing the Player from the local playerController.