/*
 * This program uses in-line assembler to read special
 * keys on the keyboard.
 * THIS WILL NOT COMPILE ON MICROSOFT VC++ 4.0 AND LATER!
 * I'm sorry Microsoft people, but your compiler sucks.
 */

#include <stdio.h>

int getkey(void);

int main()
{
    int x, i;
   char c;
   for(i=0;i<5;i++)
     {
	
    puts("Press a key to see its scan code");

    x = getkey();
    printf("The Scan code for that key is: %04X\n",x);
    printf("           The ASCII value is: %02X\n",x & 0x00FF);
    x = x & 0xFF00;
    x = x >> 8;
    printf("            The key number is: %02X\n",x);
	c = (char)x;
	printf("The key is: %c\n",c);
     }
   
}

/*
 * getKey uses the BIOS keyboard function to read
 * a key's scan code value, which is the only way
 * you can read function keys and Ctrl and Alt key
 * combinations. A 16-bit value is returned.
 */

int getkey(void)
{
	int key;

        #pragma asm mov ah, 10h
        #pragma asm int 16h
        #pragma asm mov key, ax
   

	return(key);
}


