I found the reason for this issue:
https://www.allegro.cc/forums/thread/618255
I was setting the bitmap flags to 0, which excludes ALLEGRO_CONVERT_BITMAPS.
I also needed to make sure that I deleted and recreated shaders when recreating the display.
UPDATE: and re-register both display (fair enough) and keyboard (unexpected) event sources.
and keyboard (unexpected) event sources
Sounds like a bug. It's not needed on Mac AFAICT.
[edit]
For example, if you run this code, are you saying that it won't recognize any keys after pressing 'd' to destroy and create a display?
I know that Windows keyboard handling needs a (focussed) window to receive the WM_KEY* messages but I thought that any window managed by Allegro would do.
Could you file an issue if you've got time?
If the window is re-created, so is it's keyboard event source. I don't think it's a bug. Different HWND = different keyboard source.
Isn't that an implementation detail though? From a user perspective there's nothing in the Allegro API that ties a keyboard event source to a display. Also (unless I've misunderstood what Andrew was doing) deleting the display doesn't affect the keyboard on Macos, so it is inconsistent across platforms at the least. I'm not able to test on Windows so I don't know if the code I posted works or doesn't work.
Theoretically it should be re-used. I can try it.
I tested your code and in both debug and release mode I could press the d key as many times as I wanted to before pressing q to quit, or just q to quit.
Thanks Edgar. I must have misunderstood what AG was saying the problem was.