My Solution I have resolved this for time being by running a timer every 0.333 seconds that does the following check
//is viewport no longer foreground in OS ?
if (!VictoryViewport->IsForegroundWindow())
{
//reset player input
if(PlayerInput) PlayerInput->FlushPressedKeys();
}
This does work and solves the issue, and answers my question in the main post below, which is what does the ~ / console key do.
It is however still a workaround, please examine this issue and see if you can implement a
Complete Solution
Whatever function gets called when user Alt-Tab’s out of a viewport (not in editor, single instance only),
you could have that function also call something like
if(PlayerInput) PlayerInput->FlushPressedKeys();
(I crashed my game by not including the if(PlayerInput)
in multiplayer )
Update 2: Yes you can reproduce this in single-player instance, not in editor, using steps below, and actually whatever keys you were pressing when you alt-tab out, if you press those same keys it does finally clear the input, but pressing other keys does not, so character will keep running in whatever direction it was going when you alt-tab out until you press the same input again.
ex: while holding A to run sideways, press ALT-Tab and character will keep going even when you tab back in, till you press A, other keys dont stop it.
the point:
The ALT key is also not being cleared till you press it again, which is not exactly intuitive to the person alt-tabbing or convenient for my keybinding system which relies on the value of ALT key to be correct at all times .
Update: You should be able to reproduce this with my steps below in a single player instance, again not running in editor, just the game itself.
Reproducing:
I can reliably reproduce this issue in current build by
- having two game instances / viewports open, not running editor, and having the games connected via 127.0.0.1
- have 1 character start running pressing A or D
- while holding down A or D, press ALT TAB to go to other game instance
- first character will keep running, the ALT command will not be cleared
It doesnt happen every time unless you press all the keys just right, but when it does happen it is game-breaking for me due to my custom keybinding system which relies on the ALT key being cleared,
as well as the fact that when I tab back in I cant stop the character from running sideways till I press ~ / Console which may not be available in shipping builds
Dear Friends at Epic,
I am loving UE4, thanks so much for making it!
Situation 1
I have two viewports open for testing multiplayer, I am not in the editor, I am using port 127.0.0.1
Often times if I am having 1 character running with WASD and then I tab over to the other window, the first character will keep running indefinitely as the input does not get cleared when tabbing out
that’s fine, but when I tab back in, I cannot get the character to stop running
The character has become unresponsive to new WASD input!
unless I press ~ / console key, which somehow clears the input
Situation 2
I have a custom keybinding system that checks whether LeftControl, LeftAlt and Leftshift are down (using IsInputKeyDown from PC class)
When I tab between the two viewports, the LeftControl, LeftAlt and Leftshift flags seem to get all mussed up, so that when I tab back in, the game thinks those keys are being held down,
resuming normal key pressed and even pressing CTRL ALT or SHIFT does not fix this behavior, and my keybinding system becomes broken because it thinks those keys are being held down when they are not and does not allow my key press to register (because it thinks I am pressing CTRL T for example, when I am just pressing T)
until I press ~ / console key
Then the CTRL SHIFT ALT flags get cleared and if I press just T (no ctrl or shift or alt), that is what my keybinding system gets and allows the command to pass
My Main Question
so my question is
what is the ~ / console key doing to clear the input?
Because I can manually detect when the viewport becomes foreground window and call this clearInput myself, or whatever function it is
In the long run it’d be nice if this issue could be addressed, as in the full game the console may not be available and I need some way to clear input or when tabbing back in the game engine should clear the input automatically
System Specs
I’m using Windows 7 64 bit
Thanks so much!
Rama