[AD] Problem with key_shifts on Windows. |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Hi,
I have found a bug in the behaviour of the key_shifts variable in
Windows. Sometimes, the appropriate flag does not get set when a
shift/ctrl/alt key is pressed, and when the key is released, the flag is
set.
When I run the attatched program on Windows (both W2K and W98), the
message to say if SHIFT/CTRL/ALT is held down is not displayed on
startup, not displayed when the key is pressed, but only displayed once
the key is released. Also, if a second SHIFT/CTRL/ALT key is pressed
while the first key is held down, then the flag for the first key
becomes set. If the first key is then released, the flag for the second
key is set. If however the second key is released before the first key
is released, then the flag for the second key is set.
Another thing I notice is that as long as the flag for CTRL is set, ESC
does not work, and if the flag for ALT is set, neither ESC or SPACE
works (I've not tried any other keys).
I have tried compiling my example with both MSVC6 and GCC 3.4.4
(Cygwin), and both exes produce the same result.
However, I tried the DOS version (DJGPP under W98), and it behaved as
expected (the flags were unly set while the keys they represented were
held down).
I am using Allegro 4.2.0 under both DJGPP, MSVC (both W98 and W2K) and
Cygwin.
Also in the Windows, if ALT-GR is released, it sets both the ALT and
CTRL flags in key_shifts, but in the DOS version, ALT-GR only sets the
ALT flag when pressed. I have a UK keyboard.
Incidentally, this bug manifests itself in the Allegro grabber under
Windows. I sometimes find that I end up selecting multiple-objects when
I only want to select one. If I hold down SHIFT, this problem disappears.
AE.
PS. I just noticed a thread on Allegro.cc about the same problem -
http://www.allegro.cc/forums/thread/581209
/***************************************************************************
*
* keyshifts.c
* Test program to show the key_shifts function showing stuck shift keys in Windows
*
**************************************************************************/
/****************************************************************************
Includes
*/
#include <allegro.h>
/****************************************************************************
Types
*/
typedef int TeBool;
/****************************************************************************
Defines
*/
TeBool
teSetupGfx()
{
set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
set_palette(desktop_palette);
return TRUE;
}
void
teCleanupGraphics()
{
}
void
tePrintKeyPressed(TeBool bCondition, char *szText, int nY)
{
if(bCondition)
{
textout_ex(screen, font, szText, 30, nY, 0, 1);
}
else
{
rectfill(screen,30,nY,30+text_length(font,szText),nY+text_height(font),0);
}
}
void
teDoTest()
{
TRACE("Starting test...\n\n");
textout_ex(screen, font, "Hold any combination of SHIFT, CONTROL, or ALT, release, and try again.", 0, 0, 1, 0);
while(!key[KEY_ESC] && !key[KEY_SPACE])
{
tePrintKeyPressed(key_shifts & KB_SHIFT_FLAG, "SHIFT is pressed", 20);
tePrintKeyPressed(key_shifts & KB_CTRL_FLAG, "CONTROL is pressed", 20+text_height(font));
tePrintKeyPressed(key_shifts & KB_ALT_FLAG, "ALT is pressed", 20+(text_height(font)<<1));
}
TRACE("\nEnding test...\n");
}
TeBool
teSetup()
{
if(allegro_init())
{
TRACE("Error Initialising Allegro.\n");
return FALSE;
}
if(install_keyboard())
{
TRACE("Error Initialising Keyboard.\n");
return FALSE;
}
if(!teSetupGfx())
{
TRACE("Error setting up the graphics.\n");
return FALSE;
}
return TRUE;
}
void
teCleanUp()
{
teCleanupGraphics();
remove_keyboard();
allegro_exit();
}
int main(void)
{
if(!teSetup())
{
teCleanUp();
return -1;
}
teDoTest();
teCleanUp();
return 0;
}
END_OF_MAIN();