unsigned char touches[256], enfonce[256];

enum TouchesSpeciales {
	T_SOURIS_GAUCHE=0x01,T_SOURIS_DROIT,T_ANNULER,T_SOURIS_MILIEU,
	T_RETOUR=0x08,T_TAB,T_CLEAR=0x0C,T_ENTER,T_SHIFT=0x10,T_CTRL,T_MENU,T_PAUSE,T_CAPITALE,
	T_ESCAPE=0x1B,T_ESPACE=0x20,T_PAGEUP,T_PAGEDOWN,T_END,T_HOME,T_GAUCHE,T_HAUT,T_DROITE,
	T_BAS,T_SELECT,T_SYSREQ=0x2C,T_INSERT,T_DELETE,T_HELP,
	/*Pour les touches numériques, utiliser '0' à '9'.
	Pour les touches alphabétiques, utiliser 'A' à 'Z'.*/
	T_NUMPAD0=0x60,T_NUMPAD1,T_NUMPAD2,T_NUMPAD3,T_NUMPAD4,T_NUMPAD5,T_NUMPAD6,T_NUMPAD7,
	T_NUMPAD8,T_NUMPAD9,T_FOIS,T_PLUS,T_SEPARATEUR,T_MOINS,T_POINTDECIMAL,T_DIVISION,T_F1,
	T_F2,T_F3,T_F4,T_F5,T_F6,T_F7,T_F8,T_F9,T_F10,T_F11,T_F12,T_NUMLOCK=0x90,T_SCROLL_LOCK,
	//T_ALPHA1 à T_ALPHA8 sont des "touches mortes". A tester.
	T_ALPHA1=0xBA,T_ALPHA_PLUS,T_VIRGULE,T_TIRET,T_PERIODE,T_ALPHA2,T_ALPHA3,T_ALPHA4,
	T_ALPHA5,T_ALPHA6,T_ALPHA7,T_ALPHA8,T_ALPHA9
};


#define testTouche(x)	(enfonce[x])
BOOL toucheAppuyee(unsigned char x)		{
	int i=touches[x];
	touches[x]=0;
	return i;
}

int keybhit()		{
	int i;
	for (i=0;i<256;i++)
		if (toucheAppuyee((UCHAR)i))
			return i;
	return 0;
}

#define MAX_TOUCHES 256
int nTouches=0;
unsigned char chars[MAX_TOUCHES+1];

void pushkey(int k)	{
	if (nTouches<MAX_TOUCHES-1)
		nTouches++;
	chars[nTouches]=k;
}

int getkey()	{
	if (nTouches<=0)
		return 0;
	memmove(chars,chars+1,MAX_TOUCHES-1);
	nTouches--;
	return chars[0];
}

int kbhit()	{
	if (nTouches<=0)
		return 0;
	return chars[1];
}

int getch()		{
	int i;
	while(!(i=getkey())) Sleep(1);
	return i;
}
