• C

Keyboard Handler

I need to write a set of keyboard handler functions.  It should allow me to check for multiple keypresses.  It should take over the port from the BIOS.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Why don't you want to use the BIOS. Would make it a lot easier.

What operation system you using ? DOS ? Windows ? WIN32 ?
What king of handlers you need ? You need to have callbacks caling when key pressed ? You need to check key state ?

IsaacWAuthor Commented:
The BIOS functions don't allow me to know when a key is released, so if I want to detect say, Ctrl-S for save or something, I need to overwrite it.  I'm programming for DOS in protected mode.  I have a function to handle the keypresses, I just need to know how to get it called whenever an int 9 occurs.  Thanks for all your help.
Simple Misconfiguration =Network Vulnerability

In this technical webinar, AlgoSec will present several examples of common misconfigurations; including a basic device change, business application connectivity changes, and data center migrations. Learn best practices to protect your business from attack.

Just run SetNewKbdInt() to install, and SetOldKbdInt() to deinstall. The kbdtable array has values for all the scancodes for the keys. For examples: the scan code for "Enter" is 28.
if(kbdtable[28]==1) cout << "Enter pressed";
if(kbdtable[28]==0) cout << "Enter released";

This can moniter the status of all the keys at the same time.

volatile unsigned char far kbdtable[128];

#ifdef __cplusplus
            #define __CPPARGS ...
            #define __CPPARGS

void interrupt ( *OldKbdInt)(__CPPARGS);
void interrupt NewKbdInt( __CPPARGS )
      unsigned char keyp;
      keyp = inp( 0x60 );

      if( keyp < 128 )
    kbdtable[keyp] = 1;
            kbdtable[keyp-128] = 0;

  outp( 0x20, 0x20 );

void SetNewKbdInt()
  OldKbdInt = getvect( 0x9 );
  setvect( 0x9, NewKbdInt );
  int q;
  for(q=0;q<128;q++) kbdtable[q]=0;

void SetOldKbdInt()
      setvect( 0x9, OldKbdInt );

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
IsaacWAuthor Commented:
I need to know what include files to use, getvect and setvect aren't recognized by my compiler as library functions.  I am using DJGPP v2.01.  Thanks for your help.

I think all you need is dos.h. I programmed this code to work in Turbo C++ 3.0, so you might need to change something if it doesn't work.
IsaacWAuthor Commented:
Thanks, but since I'm using DJGPP, I have to use real mode calls.  All your other code looks like I can use it, so I'll give you a B.  Thanks once again.
IsaacWAuthor Commented:
Thanks, but since I'm using DJGPP, I have to use protected mode calls.  All your other code looks like I can use it, so I'll give you a B.  Thanks once again.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.