Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity 3.5.7f6 dual shift key bug

Discussion in 'Editor & General Support' started by shaderbytes, Apr 18, 2013.

  1. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    Hi Ive encountered a bug with using two shift keys simultaneously. Im on Windows 7 and the bug happens in the editor and the web player.

    The bug happens with any Input methods of Unity "GetKey" , "GetKeyUp" and "GetKeyDown". I tried them all.

    Here are two code snippets , try each one separately you will see the bug is consistent.

    What happens is when pressing two shift keys one after another (left then right or right then left) , if you release the second shift key you pressed before releasing the first shift key you pressed - it does not register with unity.

    The bug only happens in that order .. meaning if after pressing two shift keys , releasing the first key you pressed first will work fine as well as then releasing the second shift key , so please test it as mentioned above.

    This is not a keyboard hardware problem (non n-key rollover etc) as I have some pinball engines on my computer that use dual shift keys without any problem.

    1. GetKeyUp/GetKeyDown

    Code (csharp):
    1.  
    2. if(Input.GetKeyDown(KeyCode.LeftShift)){
    3.     Debug.Log("GetKeyDown left shift");
    4. };
    5.            
    6. if(Input.GetKeyUp(KeyCode.LeftShift)){
    7.     Debug.Log("GetKeyUp left shift");
    8. };
    9.            
    10. if(Input.GetKeyDown(KeyCode.RightShift)){
    11.     Debug.Log("GetKeyDown right shift");
    12. };
    13.            
    14. if(Input.GetKeyUp(KeyCode.RightShift)){
    15.     Debug.Log("GetKeyUp right shift");
    16. };
    17.  
    2. GetKey

    Code (csharp):
    1.  
    2. if(Input.GetKey(KeyCode.LeftShift)){
    3.     Debug.Log("GetKey left shift");
    4. };
    5. if(Input.GetKey(KeyCode.RightShift)){
    6.     Debug.Log("GetKey right shift");
    7. };
    8.  
    Could someone else please test this? I did google it to see if anything popped up about newer versions of Unity having perhaps fixed this but didnt not see any results so im not sure.
     
  2. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    Really..? the zero replies downer.. AGAIN! haha

    but anyway..

    Could someone else test this?

    I would like to confirm it's not an isolated problem before filing a official bug report to Unity
     
  3. Metron

    Metron

    Joined:
    Aug 24, 2009
    Posts:
    1,137
    Checked this with the second code snippets.

    Can be reproduced:


    Start, push and hold left shift, then push and hold right shift, after a second or 2 release right shift -> Still shows up in the console... release doesn't get registered.

    Same thing if you inverse it...

    Quite consistent.

    Edit: Ah... lol... 4.1.2 here :) So not solely a 3.5 problem...
     
  4. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    Metron you are a champ Thank you.

    I have not done a bug report before but have seen there is a button to do so in the unity editor so I will start there.

    cheers
     
  5. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
  6. out-of-pixel

    out-of-pixel

    Joined:
    Mar 18, 2013
    Posts:
    3
    It's still there in 5.3.5.
     
  7. usernameHed

    usernameHed

    Joined:
    Apr 5, 2016
    Posts:
    93
    Yes... still there, very anoying
     
  8. DaRaVeNrK

    DaRaVeNrK

    Joined:
    Apr 22, 2014
    Posts:
    1
    Why is this thread still relevant? This seems like a simple fix. Is this just present in the editor or is this problem persistent beyond publishing to a standalone?
    I see that the Gui event key method is still not updating and working with the editor in 5.6.1f1 but is this in the published game after standalone Building?
     

    Attached Files:

  9. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900
    @D

    It is even worse now , the same thing is happening with the crtl keys.. i started a thread for it but no rellies in it for days... the shift bug is since unity 3 , and because it was nor fixed it has remained and propagated to the ctl keys..
     
  10. Roidz99

    Roidz99

    Joined:
    Jul 8, 2010
    Posts:
    198
    I can confirm this bug is still here on unity 2017
     
  11. Roidz99

    Roidz99

    Joined:
    Jul 8, 2010
    Posts:
    198
    And in unity 2018 !
     
  12. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    406
    Hey everyone,

    This problem has been reported numerous times on the Unity Forums, but I haven't seen anyone give an explanation for what's going on and why it hasn't been fixed. So, here it goes!

    This problem is very old, much older than Unity, because it is in fact a Windows issue (or rather limitation) which may have existed since it's inception. The deal is, Windows considers "Shift" to be a state rather than discrete key events and communicates this state via WM_KEYDOWN/UP as the combination of both left and right shift keys. That is, a WM_KEYDOWN message is dispatched when either shift key is depressed but a WM_KEYUP message is dispatched only when both keys are released.

    There is no workaround for Unity, nor any other engine/application, using these messages. Instead the "Raw Input" API, which provides the actual state of an input device (includes keyboard, mouse, and HID), must be used. However, this API, as it's name implies, doesn't perform any processing on the input so it's up to the implementer to detect and report key state changes.

    Sadly, InputManager wasn't designed to perform this kind of low-level processing and implementing the API requires a lot of work. So, we're not planning on fixing this for the "old" InputManager.

    The good news is: New Input does implement RAWINPUT and so this problem is currently "fixed" in that system. Although NewInput is still in Beta, if the Shift key is a problem for you I recommend migrating to this system.

    One final note: this bug is also present in UWP (Window Store Apps) but in this case RAWINPUT is a "banned" API and so there is no fix available yet for UWP (even with NewInput). We've communicated this problem to Microsoft and looking to get a solution from them.
     
  13. shaderbytes

    shaderbytes

    Joined:
    Nov 11, 2010
    Posts:
    900

    I had a user share some code with me to at least get this working on windows , it uses user32.dll. obviously this is just a partial fix as it cant work on mobile or other platforms, I have used this windows hack now and it worked but obviously we need a universal fix to all desktop OS , mobile does not matter as no keyboard obviously. The thing is there has to be a working solution as Zen studios , the biggest game company making digital pinball has huge licences and publishes to all platforms , all os , all devices.. and those that use a keyboard .. dual shift works.. I have a few of their games on windows 10 , and steam so I personally know it works. I have also never once seen a complaint from other users about dual shift keys so I presume it works on their platform as well..