[AD] Revenge of the key_shifts troubles.

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Hi,

I have discovered two more quirks with key_shifts and a quirk with the key[] array.

I am using Allegro 4.2.2 (with the wkeybd.c patch in http://sourceforge.net/mailarchive/forum.php?thread_name=op.tyew0wd5uugend%40killerpc1&forum_name=alleg-developers applied and no other patches)

If NUM-LOCK is active, key_shifts does not register the SHIFT key when I press down a numpad number-key (or numpad '.' key) while holding down SHIFT, but if I release the numpad key, key_shifts once again registers SHIFT. However, if I'm holding down the numpad key and I press SHIFT, the SHIFT key does become registered in key_shifts. This does not happen with the CTRL or ALT keys. If the NUM-LOCK indicator is off, this does not occur. This happens under both Windows 2000 and Windows 98. On Windows 2000 (but not on Windows 98), the same behaviour happens in the key[] array for KEY_LSHIFT and KEY_RSHIFT. This happens with the numpad numbers but not with the numbers above the letter-keys.

Another quirk I noticed is that if I start the program, the NUM-LOCK, SCROLL-LOCK and CAPS-LOCK flags are not registered in the key_shifts flag (regardless of whether or not they're on) until at least one key is pressed. This happens under both Windows 2000 and Windows 98.

Attatched is the latest version of the test-app I'm using.

AE.


/***************************************************************************
 *
 * 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
 */


/* Used to position the status of the keys */

#define TEKEYSHIFTSXPOS 80
#define TEKEYSHIFTSYPOS 60

#define TEKEYSHIFTS2XPOS 84
#define TEKEYSHIFTS2YPOS 88

#define TEKEYARRAYXPOSL 20
#define TEKEYARRAYXPOSR 288
#define TEKEYARRAYYPOS 140

#define TEKEYARRAY2XPOS 154
#define TEKEYARRAY2YPOS 168







TeBool
teSetupGfx()
{

	if( set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0))
	{
		allegro_message("ERROR: Could not set graphics mode!\n");
		return FALSE;
	}

	set_palette(desktop_palette);


	return TRUE;
}



void
teCleanupGraphics()
{

}





void
tePrintInitialContentsOfDiaplay()
{
	char *szBuildDetails, *szStaticLink;




	textprintf_ex(screen, font, 0,0, 0, 4, "Driver: %s", keyboard_driver->name);

#ifdef DEBUGMODE
	szBuildDetails = "DEBUG";
#else
	#ifdef PROFILEMODE
		szBuildDetails = "PROFILE";
	#else
		szBuildDetails = "RELEASE";
	#endif
#endif

#ifdef ALLEGRO_STATICLINK
		szStaticLink = ". STATICally linked version";
#else
		szStaticLink = "";
#endif

	textprintf_ex(screen, font, 0,8, 0, 2, "Allegro %s %s (internally %s)", ALLEGRO_VERSION_STR, ALLEGRO_PLATFORM_STR, allegro_id);
	textprintf_ex(screen, font, 0,16, 0, 2, "%s build%s.", szBuildDetails, szStaticLink);

	TRACE("Driver: %s\n", keyboard_driver->name);
	TRACE("Allegro %s %s (internally %s)\n", ALLEGRO_VERSION_STR, ALLEGRO_PLATFORM_STR, allegro_id);
	TRACE("%s build%s.\n", szBuildDetails, szStaticLink);

	textout_centre_ex(screen, font, "Hold any combination of SHIFT, CONTROL, or ALT, release, and try again.", SCREEN_W/2, 28, 1, 0);

}


void
tePrintKeyPressed(TeBool bCondition, char *szText, int nX, int nY)
{
	if(bCondition)
	{
		textout_ex(screen, font, szText, nX, nY, 0, 1);
	}
	else
	{
		rectfill(screen,nX,nY,nX+text_length(font,szText),nY+text_height(font),0);
	}
}



void
teDoTest()
{

	TRACE("Starting test...\n\n");

	tePrintInitialContentsOfDiaplay();



	while(!key[KEY_ESC] && !key[KEY_SPACE])
	{
		if(keyboard_needs_poll())
		{
			poll_keyboard();
		}


		/* Print results for key_shifts */
		tePrintKeyPressed(key_shifts & KB_SHIFT_FLAG, "key_shifts: SHIFT is pressed", TEKEYSHIFTSXPOS, TEKEYSHIFTSYPOS);
		tePrintKeyPressed(key_shifts & KB_CTRL_FLAG, "key_shifts: CONTROL is pressed", TEKEYSHIFTSXPOS, TEKEYSHIFTSYPOS+text_height(font));
		tePrintKeyPressed(key_shifts & KB_ALT_FLAG, "key_shifts: ALT is pressed", TEKEYSHIFTSXPOS, TEKEYSHIFTSYPOS+text_height(font)*2);

		tePrintKeyPressed(key_shifts & KB_SCROLOCK_FLAG, "key_shifts: SCROLL-LOCK is active", TEKEYSHIFTS2XPOS, TEKEYSHIFTS2YPOS);
		tePrintKeyPressed(key_shifts & KB_NUMLOCK_FLAG, "key_shifts: NUM-LOCK is active", TEKEYSHIFTS2XPOS, TEKEYSHIFTS2YPOS+text_height(font));
		tePrintKeyPressed(key_shifts & KB_CAPSLOCK_FLAG, "key_shifts: CAPS-LOCK is active", TEKEYSHIFTS2XPOS, TEKEYSHIFTS2YPOS+text_height(font)*2);

		/* Print results for their equivalent key[] values */
		tePrintKeyPressed(key[KEY_LSHIFT], "key[]: LEFT-SHIFT is pressed", TEKEYARRAYXPOSL, TEKEYARRAYYPOS);
		tePrintKeyPressed(key[KEY_RSHIFT], "key[]: RIGHT-SHIFT is pressed", TEKEYARRAYXPOSR, TEKEYARRAYYPOS);
		tePrintKeyPressed(key[KEY_LCONTROL], "key[]: LEFT-CONTROL is pressed", TEKEYARRAYXPOSL, TEKEYARRAYYPOS+text_height(font));
		tePrintKeyPressed(key[KEY_RCONTROL], "key[]: RIGHT-CONTROL is pressed", TEKEYARRAYXPOSR, TEKEYARRAYYPOS+text_height(font));
		tePrintKeyPressed(key[KEY_ALT], "key[]: ALT is pressed", TEKEYARRAYXPOSL, TEKEYARRAYYPOS+text_height(font)*2);
		tePrintKeyPressed(key[KEY_ALTGR], "key[]: ALT-GR is pressed", TEKEYARRAYXPOSR, TEKEYARRAYYPOS+text_height(font)*2);

		tePrintKeyPressed(key[KEY_SCRLOCK], "key[]: SCROLL-LOCK is pressed", TEKEYARRAY2XPOS, TEKEYARRAY2YPOS);
		tePrintKeyPressed(key[KEY_NUMLOCK], "key[]: NUM-LOCK is pressed", TEKEYARRAY2XPOS, TEKEYARRAY2YPOS+text_height(font));
		tePrintKeyPressed(key[KEY_CAPSLOCK], "key[]: CAPS-LOCK is pressed", TEKEYARRAY2XPOS, TEKEYARRAY2YPOS+text_height(font)*2);


		// TODO: other >= KEY_MODIFIERS keys?


	}


	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();


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/