Solved

Keyboard Handler

Posted on 1997-07-25
8
380 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.
0
Comment
Question by:IsaacW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 3

Expert Comment

by:LucHoltkamp
ID: 1252599
Why don't you want to use the BIOS. Would make it a lot easier.

.luc.
0
 
LVL 3

Expert Comment

by:jaba
ID: 1252600
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 ?

0
 

Author Comment

by:IsaacW
ID: 1252601
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
mosfet earned 300 total points
ID: 1252602
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 );
}
0
 

Author Comment

by:IsaacW
ID: 1252603
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.

0
 
LVL 1

Expert Comment

by:mosfet
ID: 1252604
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.
0
 

Author Comment

by:IsaacW
ID: 1252605
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.
0
 

Author Comment

by:IsaacW
ID: 1252606
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question