I think I fixed it:
https://www.dropbox.com/s/6p1ylcj5aepnjpz/acwin-3.4.1--try-alttabfix-2.zip?dl=0At least, I have nearly 100% reproduction with the latest 3.4.1 engine, and no reproduction with this test build.
I had to change library code, although I did not simply removed the code chunk as was suggested above. Not that I am against that, but I wanted to test if my understanding of the cause of this problem is correct. And also, in case of success, I'd like to suggest pull request to their repository.
For the reference, my changes are:
/* ignore special Windows keys (alt+tab, alt+space, (ctrl|alt)+esc) */
if (((scancode == DIK_TAB) && (_key_shifts & KB_ALT_FLAG))
|| ((scancode == DIK_SPACE) && (_key_shifts & KB_ALT_FLAG))
|| ((scancode == DIK_ESCAPE) && (_key_shifts & (KB_CTRL_FLAG | KB_ALT_FLAG))))
{
handle_key_release(scancode); // <============================= my fix =======
return;
}
A little elaboration.
What this function does: it receives key push
and release events, and passes them further into handle_key_press/handle_key_release. Before that it may skip processing under certain conditions.
Skipping Alt+Tab from passing it further into program, perhaps, may make sense, but the ambivalent meaning of this function caused it to fail.
Because when TAB key is released, if ALT key is still registered as pressed at that moment,
the TAB release event will also be ignored.
Which leads to the issue which steps of reproduction I described above:
1) you hold TAB; since ALT is not pressed yet, the press event is registered.
2) you hold ALT and then release TAB or ALT & TAB simultaneously, and release event is skipped, making program think that TAB is still pressed.
My proposed solution is to force release event for the scancode that is accompanied by ALT (TAB, space or Escape in this case).
PS.
My fix would be finding this array and everytime ags window receives focus (returning from alt+tab) all keys would get release.
I actually tried this in my previous attempt using available Allegro API, but it did not work. Maybe there was something else, but frankly I think we already spend way too much time on this problem.
PPS. Also, when game is running in windowed mode, I was able to reproduce this error without game switching out (if you hold TAB earlier than ALT, guess that's how system works). Clearing buffer on switch in/out wouldn't help in that case.