Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug Wrong input values with Windows shortcuts

Discussion in 'Input System' started by philippebedard, Sep 10, 2021.

  1. philippebedard


    Jan 20, 2021

    There's an issue with the inputs value when we use a Windows shortcut. This issue was there in 1.1.0 prev3 (both for Editor and Player). Now it seem like the 1.1.1 version fixed the issue on the Editor side, but I still have the issue on Player side.

    To reproduce:
    - Create an action with the "Ctrl" key as the binding.
    - Debug log the IsPressed() state and the ReadValue<float>() in an update loop.
    - Make a development build to see the debug log
    - Make sure you have the application focus
    - Press Ctrl+Shift+Esc (Open the Windows Task Manager) and release them
    - Click back on your application to focus on it.

    Your IsPressed() and your ReadValue<float>() will still print out a value of True and 1. Even if your Ctrl key is released. If you click back the ctrl key, everything get back to normal.

    We can reproduce the same issue with Alt+Tab (Change tab / if you use "Alt" as binding) or Ctrl+Shift (Change keyboard language).

    I created a very small standalone application to test it:

    Thanks for your help
  2. dmytro_at_unity


    Unity Technologies

    Feb 12, 2021
    It's because we currently don't explicitly poll keyboard state on some platforms when gaining focus, which makes some controls to be stuck in stale mode if I understand correctly. While we will fix it eventually, sorry I don't really have a good workaround for now.

    PS. many non-unity games are also struggling with this, especially if they are implemented via WM_KEYDOWN/WM_KEYUP usually one can find that holding a key, losing focus, then going back to the game - key will be stuck in pressed position.
  3. philippebedard


    Jan 20, 2021
    Thanks for your reply, hopefully you will find a fix or a workaround soon. Because whenever a user Alt+tab or Ctrl+shift, it mess up with my application shortcuts.. I'm using Windows platform.

    I tried some workaround like enable/disable the action map with the OnAppplicationFocus or Reset() the action. Both of them wasn't working properly, the behavior is a bit different (my ReadValue() return false which is fine, but my first "Ctrl" click when I get the focus back won't work.)