I just switched to the new Input System 1.0.0 instead of the old “Input Manager” and now seem to have a weird behavior.
I catch keypress quite simple by the following code:
protected void Update() {
if (Keyboard.current.leftArrowKey.wasPressedThisFrame)
{
Debug.Log( "key down");
}
if (Keyboard.current.leftArrowKey.wasReleasedThisFrame)
{
Debug.Log("key up");
}
}
This script is attached to a not too complex GameObject.
Now when I press the left key (and keep it pressed) the Debug output is fired only once:
[15:01:48] key down
[15:04:48] key up
When I now in preview mode click anywhere into the scene with my mouse suddenly the event is continuously fired instead each Update:
[15:41:21] key down
[15:41:21] key down
[15:41:21] key down
[15:41:22] key down
...
[15:41:38] key up
[15:41:38] key up
[15:41:38] key up
...
In summary: Before clicking anywhere I have exactly ONE output for up and down, after clicking I have a down output for every frame and according ups when releasing the key.
So my question is:
How do I get a consistent behavior? Of course I can simply “remember” that keypress in a property and use that for every following update. But is that the way it should be done? And even if I do so: Why does clicking into the scene change the behavior?