[AD] Key repeats and handling screen re-opens |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Hi all.
I just fixed a bug in the Amiga port of Allegro where certain games that had
an option to switch dynamically between full screen and windowed mode at
runtime were getting themselves into a loop. It turned out to be a
keyboard handling problem. Basically the following code (in certain games)
was to blame:
void handle_keypresses()
{
if (key[...]{
{
// Change screen mode
}
}
So let's say that handle_keypresses() is called from the game's main menu
loop (which is a busy loop). This is not nice but it's how most games seem
to work. :-(
What happens is that in my keyboard driver, I get a signal that a key has
been pressed and set key[...] to 1. The signal is associated with an open
screeen or window. So now key[...] = 1 and this triggers the code above,
which changes the screen mode. The change of screen mode usually consists
of shutting the current screen and re-opening it as a window, or vice
versa. Now because Amiga input handling (and that of most operating
systems) is handled by receiving events from a particular screen or window
source in the OS, if the user releases the key during the screen or window
change, the key up event is never received, key[...] remains 1 and when
handle_keypresses() is called again it thinks the key is still pressed and
closes and re-opens the screen or window again!
I had to put a hack in the Amiga's screen/window handling code so that when
a screen or window was closed, it set all keys to 0. ie.
for (index = KEY_A; index < __allegro_KEY_MAX; ++index)
{
key[index] = 0;
}
The questions are:
1) Is the code above the correct way of resetting all keys?
2) Is there a better way of handling this situation?
--
/-------------------------------------------------------------------\
[Hitman/Code HQ - 6502/z80/68000/604e/80x86/ARM coder - Amiga rulez!]
[VZ-200/VIC-20/MZ-700/c16/c64*10/c128*8/Plus-4/CPC464/CD32/500*2 ]
[600/1000/1200*2/A4000/SNES/N64/Dreamcast/Athlon 1100/AmigaOne ]
[Assembly Language: The most fun you can have with your clothes on! ]
\-------------------------------------------------------------------/