PRODUCT : Borland C++ NUMBER : 1291 VERSION : All OS : DOS DATE : October 25, 1993 PAGE : 1/2 TITLE : How to monitor the keyboard for multiple key presses. // This is a short demonstration of monitoring the keyboard // to determine what key or key combination is pressed at // any given time. #include #include #define TRUE 1 #define FALSE 0 // keyBoardOldHandler keeps track of old interrupt function void interrupt (*keyboardOldHandler)(...); // keyboardISR will be our new keyboard interrupt service // routine void interrupt keyboardISR(...); int keyPressed[128]; // Array specifying for each key // whether it's up or down char haveKey=FALSE; // a flag to tell us if a new // keyboard event happened void keyboardCapture() { keyboardOldHandler=getvect(9); setvect(9,keyboardISR); } void keyboardRelease() { setvect(9,keyboardOldHandler); } void interrupt keyboardISR(...) { int i,j; i=inportb(0x60); // read in scan code j=inportb(0x61); // read in command status outportb(0x61,j|0x80); // reset the keyboard controller outportb(0x61,j); // if bit 7 (high bit) is set, the key was released PRODUCT : Borland C++ NUMBER : 1291 VERSION : All OS : DOS DATE : October 25, 1993 PAGE : 2/2 TITLE : How to monitor the keyboard for multiple key presses. if(i&0x80) keyPressed[i&0x7f]=0; // if bit 7 (high bit) is 0, the key just went down else keyPressed[i&0x7f]=1; outportb(0x20,0x20); haveKey=TRUE; } void main() { int i,done=FALSE; // hook interrupt 9 keyboardCapture(); while(!done) { if (haveKey) // haveKey is set by the ISR to tell us // that the keyboard did something { haveKey=FALSE; gotoxy(1,1); clreol(); for (i=0; i<128; i++) // scan status of every key { if (keyPressed[i]) cprintf("%d ",i); } // check to see if ESC was pressed (if so, exit) if(keyPressed[1]) done=TRUE; } } gotoxy(1,2); // release interrupt 9 keyboardRelease(); } DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.