Mail Archives: djgpp/1999/08/11/03:00:46
guthrie wrote:
>
> does anyone know how to get input from the keyboard using scancodes etc
> ...to be able to bet input from the arrow keys etc?? ..
>
> I know how to get input using getch() function...in the program i'm writing
> i want to be able to have the user to choose any of the keys to use ..and
> not just letter keys.
>
> any ideas or links to info on this??
Here, I have a little set of keyboard handling stuff I like....
#include <go32.h>
#include <dpmi.h>
#include <pc.h> //For inport/outport
_go32_dpmi_seginfo info;
_go32_dpmi_seginfo my_kb;
//Define these variables...
volatile unsigned char scan;
//A place to put your scancodes...
void my_kint()
{
register unsigned char a = inportb(0x60);
register unsigned char b = a;
if(b&0x80) goto lab;
scan = (a & 0x7F);
lab:
register unsigned short d = 0x20;
a = 0x20;
outportb(d, a);
}
/*And a keyboard handling function....
This function is never called by the program. Instead, we replace the
original keyboard handling code (interrupt 9) with this function for the
duration of the program. The function gets data from the keyboard using
inportb, processes the information and stores it in the global variable
scan.
The original interrupt goes through the process of converting the keys
into ascii codes and setting shift flags and the keyboard leds and other
useless stuff that's useless and stupid. Hence I write my own simple
function that does exactly what I want.
You could have it do something else, like turn flags on and off in an
array, whatever you want. */
void main (void)
{
//Your stuff, but before you use the keyboard the way you want to...
_go32_dpmi_get_protected_mode_interrupt_vector(9, &info);
my_kb.pm_selector = _go32_my_cs();
my_kb.pm_offset = (long) my_kint;
_go32_dpmi_allocate_iret_wrapper(&my_kb);
_go32_dpmi_set_protected_mode_interrupt_vector(9, &my_kb);
/*Do those 5 lines. They store the old keyboard interrupt, and install
the function above in it's place.
Note that now that getch, and any other keyboard functions WILL NOT
WORK. If you use the function I
provided, the only way to get keys is to see what scancode is in the
global variable "scan" at some
point in time. It is suggested that you set scan to 0 once you have
processed the last scancode so that
it isn't continously detected by your code */
//Here's your program
//And when we get to the end, we clean up:
_go32_dpmi_set_protected_mode_interrupt_vector(9, &info);
_go32_dpmi_free_iret_wrapper(&my_kb);
//Restore keyboard handler to it's original state, and get rid of the
one we created out of my_kint().
}
moogla
- Raw text -