Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Trigger input events without focus on the game window

Discussion in 'Input System' started by DarkRewar, Jul 23, 2019.

  1. DarkRewar

    DarkRewar

    Joined:
    Jan 19, 2015
    Posts:
    32
    Hello everyone,

    I'm using the newest version of the Input System (v0.9), XR Legacy Input (v2.0.4) and I want to trigger my input events without having the focus on the game window.

    When the users are playing in VR, I want to do some other task on the PC but players are loosing the focus from the window and no input are triggered anymore.

    Does it exist any checkbox or option to force the Input System to listen inputs (from Oculus Touch ou Vive controller) when I'm not focusing the game ?

    Thank you by advance :)
     
  2. Shaolin-Dave

    Shaolin-Dave

    Joined:
    Apr 3, 2015
    Posts:
    32
    I really hope not. Any Unity game could be used as a keylogger.
     
  3. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    838
    Bumping this instead of creating a new thread: is there a toggle for this? Wasn't able to find one in InputSettings, some users find it annoying to have the game respond to inputs while minimized.
     
  4. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    When "Run in Background" is enabled in the player settings, devices that are capable of collecting in the background while the app is in the background (devices such as keyboards and mice are not and on some platforms, no input collection in the background is supported) are expected to keep reporting input. This includes XR devices.

    If no input on XR devices is coming through with "Run in Background" enabled, please file a ticket with the Unity bug reporter.
     
  5. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    838
    We do use XR, but when the app is in the background it is also picking up keypresses/mouse input. I'm on preview-3 right now (we're currently running a public alpha, so not in a position at the moment to upgrade) so it's possible this has already been fixed. I can check the changelog, and maybe do a quick update, then file a bug report.

    EDIT: Updated to 2019.3 and preview-6, is no longer an issue.
     
    Last edited: Mar 22, 2020
  6. annerichter

    annerichter

    Joined:
    Apr 29, 2020
    Posts:
    8
    Can I *make* my custom device be run in background? My colleague made me a little Debugging software, where i click a button and send a tcp message to my game, sorta like an external controller. It triggers all the correct functions, including Queueing a new input event for my custom device. But its not being picked up, since I was out of focus when clicking the button.

    Edit: It seems to be working how I want it in a build. What is the issue with the development runtime?
     
    Last edited: Dec 2, 2020
  7. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    I'm running into the same problem in Unity -- I want to simulate input for NPCs in my game server (running in Unity), whether or not the Game View is selected.

    However, when I'm testing locally in the Unity editors (1 editor for client, 1 editor for server),
    My NPCs (server-controlled) stop moving when I click off the Game View in the server's Unity editor, and the InputAction is reading a value of 0...
    This is.. upsetting.



    Is there any way to make my input simulating code NOT rely on the Game View? :(
    This code below runs on Update, and only works when Game View is selected:


    Code (CSharp):
    1. Keyboard npcKeyboard = ...; //Created with InputSystem.AddDevice<Keyboard>() and pairing to an InputUser
    2. using (StateEvent.From(npcKeyboard, out InputEventPtr eventPtr)) {
    3.     npcKeyboard.rightArrowKey.WriteValueIntoEvent<float>(1, eventPtr);
    4.     InputSystem.QueueEvent(eventPtr);
    5. }
     
  8. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    Last edited: Mar 14, 2021
  9. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    Okay unfortunately it's not possible.
    BUT, I believe they want to implement this in the future, because:

    I found a //TODO comment in the develop branch of the source code of InputDevice.cs from the InputSystem repository!

    At the time of writing this forum post, the //TODO comment says:
    ////TODO: finer-grained control over what devices deliver input while running in background
    //// (e.g. get gamepad input but do *not* get mouse and keyboard input)