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.

Keys getting stuck?

Discussion in 'Input System' started by mudloop, May 11, 2020.

  1. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,105
    Hi,

    I have a very simple setup. A couple of actions (of type "button") with default bindings, and no interactions or processors. I read the input with ReadValue<float> (), because that was easier to implement in my existing code than working with events. Currently no controllers are connected.

    Sometimes one of my buttons is returning 1f even though I'm not holding any keys. This mostly happens with my left button action. This action has left arrow, the "a" key, d-pad left and left stick left mapped to it.

    I noticed that it stops returning 1 after I tap the "a" key, so it seems like that's the one getting stuck for some reason. Tapping the left arrow doesn't unstuck it.
    Edit : confirmed - I added a sprite that shows when Keyboard.current.aKey.ReadValue () returns 1, and for some reason that sometimes happens when the key isn't pressed.

    It happens both in the editor and in builds. Mostly when the game gets focus again, but sometimes it happens as soon as I press any input.

    I have another button that sometimes fires (once) when I press any other button, but this happens less frequently.

    Here's how I initialize :

    Code (CSharp):
    1.         public static Controls controls;
    2.  
    3.         void Awake () {
    4.             if (controls == null) {
    5.                 controls = new Controls ();
    6.                 controls.@Player.Left.Enable ();
    7.                 controls.@Player.Right.Enable ();
    8.                 controls.@Player.Jump.Enable ();
    9.                 controls.@Player.Down.Enable ();
    10.                 controls.@Player.Dash.Enable ();
    11.             }
    12.         }
    Anything I'm doing wrong?
    I'm using Unity 2019.3.13f1 on Mac, and Input System v1.0.0 (published April 29).


    Also, when I connect my Pro Controller (both wireless and wired), it keeps spamming buttons. For instance, when I use the "listen" feature in Input System, the list is immediately filled. I've used this controller for games on my Mac (but only wirelessly), and it works fine with my Switch, so I don't think it's a faulty controller.

    Thanks!
     
    Last edited: May 11, 2020
    HumanCompiler and FIFTYTWO like this.
  2. btkal

    btkal

    Joined:
    Sep 2, 2018
    Posts:
    2
    I'm seeing the *exact* same issue. The fact that you seem to be the only person to report it (and me) yet it's so simple to reproduce makes me wonder if it's some kind of OSX issue? I'm on Catalina. I haven't tried running on Windows.

    This is with InputSystem 1.0.0 and Unity 2019.4.0f1.

    In my case it's firing the "left" event started/performed - which is incorrect - then not sending a canceled until I press it again, *and* reporting a "left" input when I directly query the action via ReadValue(). It was also happening both in the SendMessage and C# Events setup.

    and this is with basically the vanilla input system configuration when you create it.
     
  3. mudloop

    mudloop

    Joined:
    May 3, 2009
    Posts:
    1,105
    I'm still on Mojave, so it's not a Catalina-only issue. But might be a good idea to find some more common ground.
    I'm on a 2015 27" iMac, and I have a qwerty keyboard with numpad, and it's wired.

    For now I went with using the plain old input system for the keyboard, and InControl for controllers, and a custom solution for configuring actions. Works well enough, but it sucks that Unity still doesn't have a usable input system in place.
     
  4. btkal

    btkal

    Joined:
    Sep 2, 2018
    Posts:
    2
    I'm on macbook pro from about 4-5 years ago. Using the old Input for movement and new InputSystem for everything else works well as a workaround, thanks.

    for what it's worth I traced this back to https://github.com/Unity-Technologi...1761/Modules/Input/Private/Input.cs#L112-L126 and nothing in the call chain indicates it's anything but the callee of that function that has a bug, but unfortunately as far as I can find the Unity C++ code isn't open source so I can't debug further than that.
     
  5. jay3sh

    jay3sh

    Joined:
    Dec 30, 2013
    Posts:
    14
  6. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Hi @mudloop, if you haven't already, could you file a ticket with the Unity bug reporter? ("Help >> Report a Bug..." in the editor's main menu)
     
  7. Alex_May

    Alex_May

    Joined:
    Dec 29, 2013
    Posts:
    197
    I've just filed a report about this.
     
  8. Hiddenworlds225

    Hiddenworlds225

    Joined:
    Apr 18, 2017
    Posts:
    32
    Thank god this is a fresh thread, I thought it was an issue from long ago. I'll report my bug issue also. But it seems we all suffer the same thing.
     
  9. kristofferlundberg

    kristofferlundberg

    Joined:
    May 7, 2020
    Posts:
    3
    Same here! This also happend for me on the old input system so I though i'd migrate to the new system and see if the problem disappears. Sadly it didn't for me.

    I'm on a macbook pro 2015, Mojave.
     
  10. robertoalexis

    robertoalexis

    Joined:
    Sep 13, 2020
    Posts:
    1
    Same here. I'm using Unity 2020.1.5f1 running on Catalina 10.15.5. Input reports keys even when they are not pressed (I tried Input.GetKey() and Input.GetAxis() with the same results).
     
  11. mrdcturner

    mrdcturner

    Joined:
    Jan 28, 2013
    Posts:
    3
    Getting the same issue here - using left / right arrow keys and sometimes the left gets stuck.
    One workaround is to set the "Action Type" to value (I was previously using "Button").

    Hopefully that helps until the issue is properly addressed :)
     
  12. Onat-H

    Onat-H

    Joined:
    Mar 11, 2015
    Posts:
    151
    I have the same problem, running Catalina 10.15.5 and in my case the left analogue stick registers up/left input suddenly during idle...
     
  13. losingisfun

    losingisfun

    Joined:
    May 26, 2016
    Posts:
    34
    Same here for all of the above and more. Me and my colleague running 10.13 up to 10.15 this seems to be a rampant problem.

    This mostly happens when you alt-tab during edit mode. Some inputs also get inverted, as in it thinks it's 'pressed' when it's not and not pressed when it is.

    Also if you try to use SHIFT + CMD + 4 and take a screenshot, once you take the screenshot it usually ends up putting one of the inputs into a forced 'pressed' state until you jiggle that input key.

    It seems to be localised to the editor. It doesn't seem to be a problem in builds, but haven't done as many tests.
     
  14. jcasalsl

    jcasalsl

    Joined:
    Oct 6, 2020
    Posts:
    1
    I have the same problem on Ubuntu 20.04
     
  15. HarrisonMcIntyre

    HarrisonMcIntyre

    Joined:
    Nov 12, 2020
    Posts:
    2
    Same problem on Windows 10.
     
    HumanCompiler likes this.
  16. geordiemhall

    geordiemhall

    Joined:
    Jun 6, 2020
    Posts:
    20
    Same problem here, where input will just start coming from a controller that's sitting idle on my desk. Usually it's the right stick (but occasionally with left stick and d-pad too).

    On macOS Catalina 10.15.7, Unity 2020.1.10 and InputSystem 1.1.0-preview2
     
  17. bobby2dazzler

    bobby2dazzler

    Joined:
    Nov 7, 2020
    Posts:
    2
    Same here on my first try with unity tutorials (lego minigame) - stuck 'left' from the moment I hit play.

    Windows 10, 2014.4.14f
     
  18. peterahou

    peterahou

    Joined:
    May 19, 2015
    Posts:
    53
    @Rene-Damm Any news on this? Did you get a chance to take a look at the issue? We're seeing it as well on both iOS and Android.
     
  19. Foreverlimbo

    Foreverlimbo

    Joined:
    Dec 6, 2020
    Posts:
    2
    Seeing the same thing on Unity 2019.4.15f1, Input system version 1.1.0-preview.2

    Anyone ever found a fix for this?
     
  20. peterahou

    peterahou

    Joined:
    May 19, 2015
    Posts:
    53
    @Foreverlimbo We ended up switching to Rewired. It's $45 on the asset store and fixed all our problems. Definitely recommended until Unity sorts our their input system (or buys and integrates something like Rewired).
     
  21. Foreverlimbo

    Foreverlimbo

    Joined:
    Dec 6, 2020
    Posts:
    2
    Cool! For some reason, I think this is just a bug in the building of the project since when I remade the project it was all fixed. But thanks anyway, I've heard rewired is really good
     
  22. DragonSix

    DragonSix

    Joined:
    Jul 2, 2013
    Posts:
    36
    Still encountering the same issue with Input.GetKey() and Input.GetAxis().

    Unity 2018 LTS didn't have the problem, I made the transition to 2020 LTS and behold: new bugs for basic features :|

    Edit: I for sure encounter the bug regularly during in-editor playtests, affects Input.GetMouseButton too.

    EDIT2: Alright after some stress tests, it seems like this bug doesn't affect final builds of the game, only in-editor playtests.
     
    Last edited: Jun 2, 2021
    xVergilx likes this.
  23. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    2,812
    Thanks for bringing this up (found it via google).

    Got the same issue with Input.GetKey and mouse buttons with Unity 2020.3.15f1.
    Pressing and releasing RMB then nearly instantly pressing and releasing LMB causes LMB to get stuck as held.

    And indeed in build it does not reproduce. Its sure is annoying for testing purposes in editor, but at least not critical.
    Hopefully Unity Team would get this fixed at some point.
     
    Frojo likes this.
  24. zdolezal

    zdolezal

    Joined:
    Sep 27, 2017
    Posts:
    74
    Same here. I am using this in the Update method:

    precisionKeyPressed = inputActions.Modifiers.PrecissionToolModifier.ReadValue<float>() > 0;


    Which is being mapped to ALT key. Once I alt+tab from the game window and return back, it's still reporting the 1f instead of 0 until I press ALT again.

    The bad thing it's not happening on brand new project where I wanted to report that bug :-(. Weird.

    Edit: resolved with after upgrading to the latest pre version
     
    Last edited: Aug 30, 2021
  25. DrZoop

    DrZoop

    Joined:
    Feb 14, 2012
    Posts:
    20
    I have been using the new Input System for a few weeks now, recently started using input actions, and now I get stuck keys.

    -Classic input system doesn't like time scale changes.
    -New input system will temporarily ignore inputs for a few seconds after starting the game, if you don't restart Unity Editor for a while.
    -New input system keys get stuck.

    Talk about stuck between a rock and a hard place... :-(
     
  26. midsummer

    midsummer

    Joined:
    Jan 12, 2017
    Posts:
    31
    InputSystem seems to very often (but not every time) think that I'm holding down the right mouse button when I enter playmode. The button is stuck in the wrong state until I really do press it once.

    WASD controls also like to get stuck a lot. Mostly it's the key last pressed that is affected, but sometimes even keys not touched get stuck in a pressed down state. It's like there's a ghost over my shoulder randomly mashing movement buttons in playmode.

    This issue only seems to affect the editor. And only keyboard and mouse input, gamepad input for the same controls works fine. I was hoping 1.1.1 would fix this... Combined with the occasionally (read: far too often) occuring bug that makes the editor do a system beep with every keypress this is quite maddening.

    macOS Big Sur 11.6 (same problem previously with Mojave)
    Unity 2021.1.15f
    Bluetooth Magic keyboard.
     
    oxysofts likes this.
  27. zdolezal

    zdolezal

    Joined:
    Sep 27, 2017
    Posts:
    74
    Yeah @Rene-Damm , this issue is pretty critical.
    Keys being stuck after alt+tab. It is so annoying thjat it prevents us to release new update after we switched to new input system. We need to find a solution or workaround.

    It even behaves like this:
    - have keybind ALT+S
    - pres ALT+tab to switch outside game
    - switch back to the app (click on taskbar)
    - pres S => alt+s is being activated

    The pressed value is wrongly returned by ReadValue<float>() as well as by IsPressed() for the ALT key.

    The correct value is being returned when you press and release the alt.

    Input system version: 1.1.1
     
  28. zdolezal

    zdolezal

    Joined:
    Sep 27, 2017
    Posts:
    74
    For me, it's happening also in the builds, not only in the editor.

    Please, what we can do about it? I was not able to find any workaround. Either I removed the default ALT keybind or I don't know.


    Anyone else is having that issue?
    Unity 2020.3.14f1
     
  29. philippebedard

    philippebedard

    Joined:
    Jan 20, 2021
    Posts:
    6
    I had the same issue, I created a bug thread. I was not able to find any workaround either...
    I received a reply from a Unity Member and added a sample code to reproduce it. Since 1.1.1 it look ok on editor side but not for builds
    https://forum.unity.com/threads/wrong-input-values-with-windows-shortcuts.1168457/#post-7491764

    I will fill up a report like @Rene-Damm mentioned above. Hopefully this will be fixed soon.
     
  30. victoryoverall

    victoryoverall

    Joined:
    Nov 20, 2017
    Posts:
    1
    Just wanted to jump in and say I'm having the problem of "stuck key presses" in macOS, Unity 2021. I have found that this is not limited to play mode, and also not limited to the new or old input system, as it also happens when navigating in the Scene view outside of play mode, when holding the right mouse button and using WASD to navigate.

    I first noticed this when using Input Get Axis Raw in Visual Scripting (formerly Bolt) with the input axis sporadically getting stuck at 1 or -1 after releasing the keys.

    It's easy to get the keyboard buttons "stuck" by repeatedly tapping them with brief pauses in between, and at some point it acts as if the button has not been released. If any other input is received whilst stuck (mouse movement, mouse click, key press, etc.) the input becomes unstuck and the axis input resets to 0.

    Here’s a clip showing the problem: https://drive.google.com/file/d/1LQy27YUy1D6oCpzofe7cfq74BLpYMXoO/view

    This is what I’m running:
    • iMac (Retina 5K, 27-inch, 2020)
    • macOS Catalina 10.15.7
    • Unity 2021.1.19f1
    • Visual Scripting 1.6.1 (no C# scripts)
    • Standard Unity input system (not the new input system)
    • Apple Magic Keyboard (connected via Bluetooth)
    • Logitech MX Master 3 mouse(connected via Bluetooth)
    I had been using Rewired to manage input for a couple of years, and the issue never occurred in play mode during that time (and to be honest I hadn't noticed when navigating in the Scene view at that time) but I unfortunately had to stop using it as it currently doesn't work with Unity Visual Scripting (it used to work with Bolt)

    Im curious if all the above reports are from users on macOS, like myself and some of the users at the top of this thread?
     
  31. dmytro_at_unity

    dmytro_at_unity

    Unity Technologies

    Joined:
    Feb 12, 2021
    Posts:
    212
    Hi folks,

    So Alt being stuck when doing Alt+Tab is being tracked here: https://issuetracker.unity3d.com/is...t-was-true-before-minimizing-the-build-window

    TL;DR it's happening because we're relying on RawInput for keyboard inputs, but when you're Alt+tabing back to the player we don't know the state of the keyboard. Old input system is resetting all keys to be "not pressed" when application loses focus (and by that triggering anything that listens to Alt KeyUp, IIRC there is a bug for that also), new system currently doesn't touch anything so Alt is set to press for whole duration of player being in background.

    I need to check but one way to work around it right now is to force reset all devices on focus gain by changing this setting to reset all:
    upload_2021-10-11_13-56-8.png
    Otherwise another workaround is to pinvoke directly to
    GetAsyncKeyState
    on focus gain and resync state of alt keys and then queue event/change controls to update keyboard state.

    A proper fix on our side would to properly resync keyboard state on focus gain. Also likely controls need to become ternary: they either have state (pressed/not pressed) or have unknown state, because realistically when losing focus we don't know the state of the keyboard anymore, and not to trigger KeyUp handlers when losing focus we need a third state.

    Stuck keys in macOS seems to be another issue all together
    @victoryoverall can you file a bug report for that please? it seems like something else prevents normal keyboard operation, as both old and new systems getting stuck
     
  32. bitinn

    bitinn

    Joined:
    Aug 20, 2016
    Posts:
    952
  33. uwdlg

    uwdlg

    Joined:
    Jan 16, 2017
    Posts:
    90
    I have a similar problem in WebGL: keys pressed when the cursor leaves the WebGL canvas become "stuck". My idea for a workaround would be to check when the cursor leaves the canvas and manually "reset" the key states. Problem is: how can I do that? Using PlayerInput#Deactivate and Activate after doesn't seem to reset key states, neither does disabling and enabling or removing and adding the keyboard input device.
     
    AdionN likes this.
  34. dead_byte_dawn

    dead_byte_dawn

    Joined:
    May 7, 2015
    Posts:
    16
    Can Confirm this is happening to me in Version 2021.1.7f1. Recreated project in a new scene still occurring. Thought it might be an EventSystem bug but now I'm out of ideas. Also, this is ONLY happening in Editor mode. It doesn't happen in Windows Builds. Hope this helps.
     
  35. Vincent13122

    Vincent13122

    Joined:
    Oct 26, 2014
    Posts:
    128
    Oh no I thought this was a bug in my code - even though it didn't make any sense, I've wasted a lot of time trying to find the problem. Learning that this is an editor bug now is very frustrating. This has been happening to my attack button for 2-3 months and also to my movement ones today all of the sudden (Which is why I thought it cant be a problem with my code). I'm using the old input system on 2020.3.24f1. Also I am on windows 10.
    I am not 100% sure but I believe it always follows a short lag spike during which the key is pressed.
     
    Last edited: Dec 16, 2021
  36. AdionN

    AdionN

    Joined:
    Nov 6, 2019
    Posts:
    7
    You not only one who have this. I have it as well, tried 2019, 2020, 2021 unity versions also legacy and new input systems.
    It is said it was fixed ages ago. But it seems that was not the case.
    https://issuetracker.unity3d.com/issues/webgl-input-dot-getkey-gets-stuck-when-changing-focus

    I tried multiple workaround but it seems we cannot reset WebGL input from Unity. Neither I found a way to do it from JavaScript. I guess we are stranded a bit with this one;.
     
  37. Shminkle

    Shminkle

    Joined:
    Nov 2, 2017
    Posts:
    1
    Same here been running into that issue.
     
  38. wilgieseler

    wilgieseler

    Joined:
    Oct 17, 2013
    Posts:
    30
    Happening for us too, in macOS 12.1 (21C52) and Unity 2021.2.7f1.

    This seems like an extremely critical bug given that we cannot control our game reliably!
     
  39. Dennis_0172

    Dennis_0172

    Joined:
    Nov 19, 2021
    Posts:
    4
    I have the same issue, this is a critical bug for my game...
     
  40. BurningThumb

    BurningThumb

    Joined:
    Apr 28, 2008
    Posts:
    86
    Same problem on Unity 2022.1.0b5 on macOS 12.2. Tried both the new and old input systems. Using WASD controls and they just get stuck making the game very difficult to control. Seems to be an editor only issue for me.
     
  41. ahsen35813

    ahsen35813

    Joined:
    Sep 15, 2019
    Posts:
    8
    Same issue on macOS 12.2. Very annoying when keys just get stuck and, for example, my car just keeps spinning faster and faster and I have no idea what went wrong :p. I really hope Unity devs see this thread soon, because this is a very major issue and it has been happening for a as long as I have been using Unity (around 4 years)
     
  42. adslitw

    adslitw

    Joined:
    Aug 23, 2012
    Posts:
    233
  43. swantonb

    swantonb

    Joined:
    Apr 10, 2018
    Posts:
    105
    Guys, i've been struggling with this for a while too. The fix is in new input system v1.3.0 which isnt showing in package manager unless you add it manually from git url: newinputsystem@1.3.0 or something like that. So to save you the headaches that's what you need to do. Works in unity 2021.2.7 at least, dont know about earlier versions
     
  44. aaronm64

    aaronm64

    Joined:
    Nov 24, 2018
    Posts:
    17
    @swantonb and @dmytro_at_unity I was so excited when I saw both of your answers, but unfortunately neither of them seem solve the issue on my end. I haven't tried 1.3.0 on Windows yet to see if it fixes the bug there, but the keys (e.g. Keyboard.current.altKey.isPressed) do still become stuck in an inverted state on Mac when refocusing the app while the physical key is pressed.
    My apologies for being an a*****e, but I have a lot of inappropriate words for the team working on this package. This issue has been around for a long time, and keyboard input seems like an important feature for a game engine to get right.

    Fyi case #1402940
     
    Last edited: Feb 13, 2022
  45. swantonb

    swantonb

    Joined:
    Apr 10, 2018
    Posts:
    105
    Damn, sorry about that. On windows it solved the issue :(. Did you also set "reset and disable all devices" in project settings?
     
  46. aaronm64

    aaronm64

    Joined:
    Nov 24, 2018
    Posts:
    17
    @swantonb sorry for late reply, but I did set "reset and disable all devices" in project settings while using the InputSystem 1.3.0 package. It works properly on Windows for me now too, but still not on macOS. Even on the latest Unity 2021.2.12f1
     
    swantonb likes this.
  47. BinaryRavine

    BinaryRavine

    Joined:
    Oct 30, 2021
    Posts:
    6
    Can you please share the link?
     
  48. thoughtware

    thoughtware

    Joined:
    Jan 31, 2022
    Posts:
    1
    Running into this issue in 2022 on MacOs with Unity 2020.3.26f1 in Game mode.
     
  49. SalvoSoftware

    SalvoSoftware

    Joined:
    Feb 4, 2013
    Posts:
    8
    I have this issue on Unity 2021.3.1 using Input System 1.3 and with changed Background Behavior setting.
    But I'm not sure it's the same issue... it only happens to me while using the gamepad, not with keyboard.
    Also the left analog resets if the position of the analog is straight up. I've tried with two gamepads and I still have the issue.
     
unityunity