We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Keyboard Handler

IsaacW
IsaacW asked
on
Medium Priority
414 Views
Last Modified: 2012-06-21
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.
Comment
Watch Question

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

.luc.

Commented:
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 ?

Author

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.
Commented:
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 ...
#else
            #define __CPPARGS
#endif

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

      if( keyp < 128 )
    kbdtable[keyp] = 1;
  else
            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 );
}

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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.

Commented:
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.

Author

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.

Author

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.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.