KC> Can anyone direct me to a good set of docs on programming the
KC> keyboard under DOS? I was hoping to avoid using the Bios functions and
KC> write my own handler, but it seems that in intermixing C code with the
KC> handler I have it fails to work.
You could look at the PCGPE - PC Game Programmers Encyclopedia which got
some stuff on this.
And maybe this will help
#include
#include
const int KEYINTR = 0x09;
const int KEYPORT = 0x60;
class ISR
{
public:
ISR(int IntrNr,void interrupt (*MyHandler)(...))
{
Intr = IntrNr;
Handler = MyHandler;
OldHandler = getvect(Intr);
Init();
}
~ISR()
{
Reset();
}
void Init() {setvect(Intr,Handler);}
void Reset(){setvect(Intr,OldHandler);}
int InterruptNo(){return Intr;}
int IsSet(){return Handler==getvect(Intr) ? 1 : 0;}
// returns 1 if interrupt is set
protected:
int Intr;
void interrupt (*OldHandler)(...);
void interrupt (*Handler)(...);
};
char Key;
void interrupt MyHandler(...)
{
Key = inportb(KEYPORT); // get key scancode at keyboard port (0x60)
cout << "Scancode : 0x" << hex << (int)Key;
if(Key==0xE0)cout << " Next Key is an extended key" << endl;
else
{
cout << " Key : 0x" << (int)(Key&0x7F);
if((Key&0x80)==0)cout << " key pressed " << endl; // bit 7 = 0
else cout << " key released " << endl; // bit 7 = 1
}
outportb(0x20,0x20); // acknowledge the interrupt
}
int main()
{
ISR KeyboardHandler(KEYINTR,MyHandler);
// set up interrupt handler "MyHandler" at interrupt "KEYINTR" (0x09)
// the interrupt is set back to the original handler when KeyboardHandler
// is destroyed
while(Key!=0x81); // Esc released = 0x81
return 0;
}
Niels...
--- GEcho 1.11+
---------------
* Origin: Free sex on Softwareboard 0224-218587 {+} Reg.Only (2:280/112)
|