InputStates lost when windows loses focus
by Daan Broekhof · in Torque Game Engine · 09/27/2004 (12:14 pm) · 3 replies
While running Torque windowed, and you switch to another window and then go back, the inputState of keyboard/mouse/joystick is forgotten (they are all activated again on window re-entry regardless of what the state was when the window lost focus).
Example:
Running the example-fps windowed, run the mission, type 'u' to chat - keep a key pressed, the key is repeated. (this is correct)
Now alt-tab away and then alt-tab back.
Holding a key down now doesn't repeat the character. (this is incorrect)
This is because the keyboard input is activated when you tab back to the window, and absorbs all repeat keys from holding down a key. This keyboard input was deactivated before the alt-tab.
Fix:
Adding 'smLast*Activated' to the Input class:
platform/platformInput.h, after 'static bool smActive;' add:
platformWin32/winInput.cc, after 'bool Input::smActive;' add:
platformWin32/winInput.cc, in Input::init, after 'smActive = false;' add:
platformWin32/winInput.cc, in Input::activate replace:
platformWin32/winInput.cc, in Input::activate replace:
platformWin32/winInput.cc, in Input::activate replace:
platformWin32/winInput.cc, in Input::deactivate, add before ' dInputManager->deactivateKeyboard();':
Then all states should be remembered between deactivating and activating.
I don't know if this bug is also present in the Linux or Mac code variants..
But the x86UNIXInputManager has a similar way of activating all when activated, with a comment why all get activated again:
platformx86UNIX/x86UNIXInputManager.cc:
But this probably is only meant for the *first* activation of the Input, to circumvent botched config settings. The above fix should be better then this solution, as it only activates all on first init, and not on every window defocus/focus.
The mac version only does mouse activation and de-activation.. but perhaps should also remember the last state instead of always activating the mouse.
(excuses if this explanation seems a bit garbled, getting all the terms straight is a bit of a hassle as there are some floating around which can be easily confused for the other - active, inactive, enabled, disabled, inputState, aquired et all ;))
Example:
Running the example-fps windowed, run the mission, type 'u' to chat - keep a key pressed, the key is repeated. (this is correct)
Now alt-tab away and then alt-tab back.
Holding a key down now doesn't repeat the character. (this is incorrect)
This is because the keyboard input is activated when you tab back to the window, and absorbs all repeat keys from holding down a key. This keyboard input was deactivated before the alt-tab.
Fix:
Adding 'smLast*Activated' to the Input class:
platform/platformInput.h, after 'static bool smActive;' add:
static bool smLastKeyboardActivated; static bool smLastMouseActivated; static bool smLastJoystickActivated;
platformWin32/winInput.cc, after 'bool Input::smActive;' add:
bool Input::smLastKeyboardActivated; bool Input::smLastMouseActivated; bool Input::smLastJoystickActivated;
platformWin32/winInput.cc, in Input::init, after 'smActive = false;' add:
smLastKeyboardActivated = true; smLastMouseActivated = true; smLastJoystickActivated = true;
platformWin32/winInput.cc, in Input::activate replace:
if ( dInputManager->isKeyboardEnabled() )
dInputManager->activateKeyboard();
with:
if ( dInputManager->isKeyboardEnabled() && smLastKeyboardActivated )
dInputManager->activateKeyboard();platformWin32/winInput.cc, in Input::activate replace:
if ( dInputManager->isMouseEnabled() )
dInputManager->activateMouse();
with:
if ( dInputManager->isMouseEnabled() && smLastMouseActivated )
dInputManager->activateMouse();platformWin32/winInput.cc, in Input::activate replace:
if ( dInputManager->isJoystickEnabled() )
dInputManager->activateJoystick();
with:
if ( dInputManager->isJoystickEnabled() && smLastJoystickActivated )
dInputManager->activateJoystick();platformWin32/winInput.cc, in Input::deactivate, add before ' dInputManager->deactivateKeyboard();':
smLastKeyboardActivated = dInputManager->isKeyboardActive();
smLastMouseActivated = dInputManager->isMouseActive();
smLastJoystickActivated = dInputManager->isJoystickActive();Then all states should be remembered between deactivating and activating.
I don't know if this bug is also present in the Linux or Mac code variants..
But the x86UNIXInputManager has a similar way of activating all when activated, with a comment why all get activated again:
platformx86UNIX/x86UNIXInputManager.cc:
// hack; if the mouse or keyboard has been disabled, re-enable them.
// prevents scripts like default.cs from breaking our input, although
// there is probably a better solution
mMouseEnabled = mKeyboardEnabled = true;
activateMouse();
activateKeyboard();
activateJoystick();But this probably is only meant for the *first* activation of the Input, to circumvent botched config settings. The above fix should be better then this solution, as it only activates all on first init, and not on every window defocus/focus.
The mac version only does mouse activation and de-activation.. but perhaps should also remember the last state instead of always activating the mouse.
(excuses if this explanation seems a bit garbled, getting all the terms straight is a bit of a hassle as there are some floating around which can be easily confused for the other - active, inactive, enabled, disabled, inputState, aquired et all ;))
#2
It's not a major bug by any means but one of those little annoyances that go against what you expect. I actually noticed it with the console, and since it effects ALL keys, it effects the arrows. It's really annoying to try to scroll 50 characters along a line, having to repress once for each character!
Thanks again Daan.
10/03/2004 (9:21 pm)
Thanks Daan! I haven't tried this yet but will tonight. It's funny but after purchasing Torque, this was the FIRST strange thing I noticed, and it was only after about 10 minutes of playing around.It's not a major bug by any means but one of those little annoyances that go against what you expect. I actually noticed it with the console, and since it effects ALL keys, it effects the arrows. It's really annoying to try to scroll 50 characters along a line, having to repress once for each character!
Thanks again Daan.
#3
08/08/2005 (7:47 pm)
Issue #248, fixed for win32 - still to be vetted on Mac/Linux.
Torque Owner Ritchey "Hawk" Mulhollem