Jump to content

[Solved] [1.12.2] Check if the game is in the foreground


Recommended Posts

Posted (edited)

I am creating a mod that interfaces with the Logitech LED SDK to access the lighting of certain G-series keyboards. In any game that either interfaces with the LED SDK natively or is added via a profile in the Logitech Gaming Software switches from its specific lighting profile to the standard profile when it goes out of focus and back when it regains focus. To achieve this I need to check if the game window is in focus. When the player is in a world I can use a client tick event handler and check for Display.isActive() every tick but if I am in the main menu the tick handler is not running and therefore the profile switching doesn't work. Is there a way to get notified of a change in the window focus (kinda like the WindowListener in Swing)?

 

This is the code I am currently using:

private boolean focused = true;

@SubscribeEvent(priority = EventPriority.LOWEST)
public void onClientTick(TickEvent.ClientTickEvent event)
{
    if (Display.isCreated())
    {
        if (focused && !Display.isActive())
        {
            focused = false;
            //shutdown lighting
        }
        else if (!focused && Display.isActive())
        {
            focused = true;
            //restart lighting
        }
    }
}

 

Edited by XFactHD
Posted (edited)

This thread discussed how to get a window handle and might be useful to you: http://www.minecraftforge.net/forum/topic/63434-1122-hooking-into-lwjgl-minecraft-window-to-add-macos-touch-bar-features/

 

Also, I think there is a RenderTickEvent. That should probably tick no matter whether you're in a world or in main menu. Note that that event is called a couple times per tick so you should check the phase (like START).

 

Edited by jabelar

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

The first hint is definetly interesting but unfortunately it doesn't allow me to attach some kind of callback.

 

The RenderTickEvent however is the perfect solution, I don't know why I didn't think of that. Thank you very much for that.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.