Mail Archives: djgpp/1997/12/02/05:01:48
Paul Cartwright wrote:
> does anyone know an algorithm that will get the scan code from a
> pressed key?
The procedure below will gets the scan code from a pressed key, and
prints it to screen if it's not in the normal character set (i.e. if
it's something strange like the arrow keys). I hope this helps...
#include "dos.h"
#include "stdio.h"
char y;
getkey(void) {
union REGS r;
r.h.ah = 0;
return int86(0x16, &r, &r);
}
main() {
union scan {
int c;
char ch[2];
} sc;
do {
sc.c=getkey();
if(sc.ch[0]==0)
printf("special key number %d \n", sc.ch[1]);
else
{
putchar(sc.ch[0]);
printf("\n");
}
} while(sc.ch[0]!='q');
}
--
Walter Luke aka "Night Watchman"
mailto:NightWatchman AT Sacrilege DOT com
Visit Shadows at http://shadows.sacrilege.com
- Raw text -