The question is more - should there be a key up event?
One could argue either way on that, with the argument that if you don't you will think that keys that were once pressed are never released perhaps deciding in favour of saying that you should.
But my question was actually much more down-to-earth than that. Assuming the Windows port is the same as the OS X port, we simply pass along events that we receive from the operating system. If the OS never tells us that the key is no longer held down, then we need to do something special. If it does, there is a bug in the recording of the key state (I doubt that, if it's done the same as on OS X anyway, since the keyboard state should be updated as soon as the event is received, but worth checking anyway).
For what it's worth, the behaviour on OS X (with ex_keyboard_events) seems to be that a KEY_UP event is generated the next time the same key is pressed after we regain keyboard focus, which is also weird. Haven't looked into this.
Why can't Allegro 5 just refresh the key states when it regains focus?
Who says it can't? But the way it currently works is that Allegro keeps track of key up/down events for you. The keyboard state is updated incrementally.
The problem is actually not straightforward. When should Allegro send up/down events (and update the keyboard state)? Probably when the program re-gains focus. In that case you need to compare the keyboard states before and after the switch and then generate events that will make up the differences.
I immensely prefer reading the key states as opposed to reading the key events.
You are free to do that.
After getting used to it, I vastly prefer using the events rather than the state, mostly because with A4, I was converting that into up/down events anyway.
I mention this because I have an input library for A4 that checks the key states and produces key press/release/held/open states based on them.
So did I and it now updates them based on the keyboard event it gets passed. It really doesn't make that much of a difference and has the aesthetic advantage of only updating stuff when it knows that there is stuff to update (or we wouldn't have received a keyboard event in the first place). The rest of the time we can idle/sleep.