Joystick/window focus

Issue #965 wontfix
Michael Columna created an issue

I am making a tool for my livestream and I want to be able to see what inputs I am pressing on my gamepad. when the window is not selected It wont recognize that a button is down. so I would like to have an option (or two) that are something like: love.joystick.setGlobal(Boolean state) -- or something similar where the game picks up the input whether or not it is focused or love.window.setFocus(state focus) where the state can be "alwaysTop" for always on top "top" to set as the active window "bottom" to set as an inactive/bottom window etc... This would help me a lot thanks.

Comments (4)

  1. Alex Szpakowski

    You can do this to allow joystick events when LÖVE is in the background:

    local ffi = require("ffi")
    
    ffi.cdef[[
    typedef enum
    {
        SDL_FALSE = 0,
        SDL_TRUE = 1
    } SDL_bool;
    
    SDL_bool SDL_SetHint(const char *name, const char *value);
    ]]
    
    local sdl = ffi.os == "Windows" and ffi.load("SDL2") or ffi.C
    
    sdl.SDL_SetHint("SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS", "1")
    

    I don't think LÖVE will have an always-on-top focus mode for keyboard and mouse events, though.

  2. Bart van Strien

    This is probably fairly niche, I can think of little reason to have games continue without focus. At least for now, using the ffi, or setting the environment variable beforehand, is probably good enough.

  3. Mi 28

    I can think of multiple scenarios where the game window loses focus but the game is still supposed to register gamepad inputs. In fact I can think of multiple scenarios where it should register all inputs even when out of focus. Such as when being played in kiosk mode and some background window intercepts the focus which is not visible due to the kiosk mode enabled; the game window appear to be in focus but it cannot register any input, and unless the kiosk box has a mouse handy it's impossible to focus back into the game window, rendering the game completely unplayable and the kiosk completely unusable.

    So while not normally necessary, it should at least be an option.

  4. Log in to comment