Search Issue Tracker

Postponed means that the issue was either a feature request or something that requires major refactoring on our side. Since that makes the issue not actionable in the close future we choose to close it as Postponed and add it on our internal roadmaps and technical debt pages instead.

Postponed

Votes

2

Found in

4.3.1f1

Issue ID

582734

Regression

No

Key gets stuck in pressed state after GUI.FocusControl

IMGUI

-

To reproduce:
1. Open attached project
2. Open scene
3. Enter play mode
4. Press and hold A - a label should appear
5. While holding A press enter (GUI.FocusControl is called)
6. Release A - it's still in the pressed state according to the label

Removing the GUI.FocusControl line from the script stops the problem

Comments (1)

  1. HamsterCrack

    Jul 12, 2014 07:12

    I just ran into this in Unity 4.5.1f3. If you run FocusControl(), then any keys that were in the DOWN state prior to that are stuck in that state when you get out of it. Presumably related to key events going to whatever manually manages their state.

    This tells me that Unity probably will have similar bugs related to application task switching or minimization. In fact, I've also seen it reported for level switching.

    EXPECTED
    Unity needs to either use some sort of polling mechanism with the hardware, or needs to recognize these context switches and call some sort of "reset to proper state". For key state, at least just running through the ones in the DOWN state.

    WORKAROUND
    I couldn't find a way to manually clear specific key states, so am using Input.ResetInputAxes(). That solution has some other issues, of course.

    MORE DETAIL
    Basic flow:

    Update()
    {
    Debug.Log(Input.GetKey(Return));
    }

    OnGUI()
    {
    if (special state)
    FocusControl()
    }

    Output:
    * FALSE
    * FALSE
    * FALSE
    press key
    * TRUE
    * TRUE
    enter special state
    * TRUE
    * TRUE
    release key
    * TRUE (wrong)
    * TRUE (wrong)
    exit special state
    * TRUE (wrong)
    * TRUE (wrong)
    press key
    * TRUE (right)
    * TRUE
    release key
    * FALSE
    * FALSE

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.