From: andyrew1@aol.com (Andyrew1) Newsgroups: rec.games.programmer Subject: Re: keyboard routines of FOF Date: 10 Feb 1995 17:35:03 -0500 Here is a keyboard interrupt i wrote for watcom in protected mode Some basic definitions of keys #define KEY_BUFFER 0x60 #define KEY_CONTROL 0x61 #define INT_CONTROL 0x20 #define KEYBOARD_INT 0x09 // make and break codes for the arrow keys #define MAKE_RIGHT 77 #define MAKE_LEFT 75 #define MAKE_UP 72 #define MAKE_DOWN 80 #define MAKE_A 30 #define MAKE_S 31 #define MAKE_D 32 #define MAKE_W 17 #define MAKE_PLUS 78 #define MAKE_MINUS 74 #define MAKE_B 48 #define MAKE_N 49 #define MAKE_ENTER 28 #define MAKE_P 25 #define MAKE_L 38 #define BREAK_RIGHT 205 #define BREAK_LEFT 203 #define BREAK_UP 200 #define BREAK_DOWN 208 #define BREAK_A 158 #define BREAK_S 159 #define BREAK_D 160 #define BREAK_W 145 #define BREAK_PLUS 206 #define BREAK_MINUS 202 #define BREAK_B 176 #define BREAK_ENTER 156 Im sure you can add others that you might need. void (__interrupt __far *Old_Isr)(); // holds old keyboard interrupt handler volatile int kbdtable[256]; // table of key presses low 128 is current // high 128 has been volatile char ct1; // keyboad interrupt vars volatile int ct2; #pragma off (check_stack) void _interrupt _far pkbd_int() { _enable(); ct1=inp(KEY_BUFFER); ct2=(int)ct1; ct1=inp(KEY_CONTROL); ct1|=0x82; outp(KEY_CONTROL,ct1); outp(KEY_CONTROL,ct1&0x7f); outp(INT_CONTROL,0x20); if(ct2>128) { *(kbdtable+(ct2-128))=0; } else { *(kbdtable+ct2)=1; *(kbdtable+(ct2+128))=1; } } #pragma on (check_stack) void setbiosisr() { _dos_setvect(KEYBOARD_INT, Old_Isr); keyloop=biosloop; /* just a void function for the loop */ } void setrawisr() { _dos_setvect(KEYBOARD_INT, pkbd_int); memset(kbdtable,(char)0,256); keyloop=keycodeloop; /* ibid biosisr */ } void installlowisr() { Old_Isr = _dos_getvect(KEYBOARD_INT); setrawisr(); } The lower 128 bytes of the keytable should be used to test if the key is currently pressed. The upper 128 bytes should be used to check if the key was pressed. The program should clear the appropriate key after it has answered the fact that the key was pressed. An example of checking the table....... void keycodeloop() { if(*(kbdtable+MAKE_LEFT)) /* these answer the lower 128 bytes and */ movcamx(-mv); /* are just used if the key is currently */ if(*(kbdtable+MAKE_RIGHT)) /* pressed. */ movcamx(mv); if(*(kbdtable+MAKE_UP)) movcamy(mv); if(*(kbdtable+MAKE_DOWN)) movcamy(-mv); if(*(kbdtable+MAKE_PLUS)) movcamz(mv); if(*(kbdtable+MAKE_MINUS)) movcamz(-mv); if(*(kbdtable+MAKE_S)) rcamx(5); if(*(kbdtable+MAKE_W)) rcamx(-5); if(*(kbdtable+(MAKE_ENTER+128))) { /* these answer the upper 128 bytes */ rotmode=(rotmode+1)%2; /* and are used if the key was pressed */ *(kbdtable+(MAKE_ENTER+128))=(char)0; /* any time in the past. They are */ } /* responsable for clearing the table */ if(rotmode) { if(*(kbdtable+MAKE_A)) rcamy(5); if(*(kbdtable+MAKE_D)) rcamy(-5); } else { if(*(kbdtable+MAKE_A)) rcamz(5); if(*(kbdtable+MAKE_D)) rcamz(-5); } if(*(kbdtable+(MAKE_B+128))) { bt=(bt+1)%3; switch(bt) { case 0: setnbf(); break; case 1: setbf(); break; case 2: setbfz(); break; } *(kbdtable+(MAKE_B+128))=0; } if(*(kbdtable+(MAKE_N+128))) { dt=(dt+1)%2; switch(bt) { case 0: setnbf(); break; case 1: setbf(); break; case 2: setbfz(); break; } *(kbdtable+(MAKE_N+128))=0; } if(*(kbdtable+(MAKE_L+128))) { setbiosisr(); *(kbdtable+(MAKE_L+128))=(char)0; } if(*(kbdtable+129)) ndonekey=0; if(*(pos+1)<0) *(pos+1)=FABS(*(pos+1)); } I hope this helps you out....