Search Issue Tracker
By Design
Votes
0
Found in [Package]
1.8.2
Issue ID
ISXB-390
Regression
No
anyKey.isPressed still runs when using alt+tab to return to build
How to reproduce:
1. Open the attached “AltTab” project
2. Build and Run the project with the “SampleScene” Scene
3. Alt+Tab out of the Build and back
Expected result: The Scene is colored blue (anyKey.isPressed is no longer running)
Actual result: The Scene is colored red (anyKey.isPressed is still running)
Reproducible with: 1.4.4 (2021.3.15f1)
Reproduced on: Windows 10
Note:
- CQA Could not test the issue
- Issue disappears if Alt is pressed again in Build
- Not reproducible in Editor
- Similar issue was reported: [https://issuetracker.unity3d.com/issues/alt-tabbing-out-of-build-leaves-the-alt-key-pressed-on-return|https://issuetracker.unity3d.com/issues/alt-tabbing-out-of-build-leaves-the-alt-key-pressed-on-return|smart-link]
UPDATE:
This behavior occurs because the InputSystem's [Background Behavior setting|https://docs.unity3d.com/Packages/com.unity.inputsystem@1.8/manual/Settings.html#background-behavior] is set to "Ignore Focus", which is by design.
When "Ignore Focus" setting is used, InputSystem does nothing to reset or re-sync devices when focus is regained, meaning the keyboard state will not automatically update when switching back to the app. In this scenario, since Windows only send key events to the focused app, the "KeyUp" message for the Alt key is missed by InputSystem causing isPressed to report true when focus is regained.
When using the "Ignore Focus" setting, the app must manually issue a [sync request|https://docs.unity3d.com/Packages/com.unity.inputsystem@1.8/manual/Devices.html#device-syncs] to ensure the keyboard (and possibly other devices) are updated.
For example:
Application.focusChanged += (bool value) =>
{
if (!value) return;
foreach (var device in InputSystem.devices)
{
InputSystem.TrySyncDevice(device);
}
};
Admittedly the documentation for this setting isn't very clear on this (at least to me), and so we'll update it to be more explicit.
In general, the Background Behavior settings is intended for very specific scenarios and shouldn't be changed unless necessary. For details on this setting, it's intended purpose, and expected functionality please see this PR: https://github.com/Unity-Technologies/InputSystem/pull/1324
-
darbotron
Mar 06, 2023 17:34
Having a similar issue:
* Keyboard.anyKey.wasPressedThisFrame intermittently stops working after alt-tab / using the windows game bar and switching back
* individual keyboard keys accessed through their controls seem fine
* seems more prone to messing up when no gamepads are connected (i.e. just mouse & keys)
* in builds 30-50% repro
* in editor maybe 5%
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- [Android] "SHADOWS_SCREEN" set as shader Keyword when no "_ShadowMapTexture" is bound leads to freeze on a build on some Mali GPU devices
- Constant console errors when using Min/Max Slider in PlayMode
- The global scene list is overridden in a project built with command line when the Override Global Scene List setting is disabled in the build profile
- [Linux] AutoLocale log is logged when opening a project
- Global Scenes are not included in the Build when building multiple Build Profiles at the same time
Resolution Note:
This behavior only occurs when the InputSystem setting "Background Behavior" is set to "Ignore Focus", which is intended functionality. It does not occur when Background Behavior is set to the other values nor when "Run in Background" setting is set false.
The "Background Behavior" setting is intended for very specific scenarios and generally shouldn't be changed unless absolutely necessary. Please see the Update in the description for more details.