delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/11/03:00:46

From: Neil Goldberg <ngoldber AT mitre DOT org>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: kebaord input
Date: Mon, 09 Aug 1999 13:16:47 +0100
Organization: The MITRE Corporation
Lines: 78
Message-ID: <37AEC6AF.4AAC@mitre.org>
References: <7olkks$ec0$1 AT garnet DOT nbnet DOT nb DOT ca>
NNTP-Posting-Host: mm58842-pc.mitre.org
Mime-Version: 1.0
X-Trace: top.mitre.org 934218872 17186 128.29.96.60 (9 Aug 1999 17:14:32 GMT)
X-Complaints-To: usenet AT news DOT mitre DOT org
NNTP-Posting-Date: 9 Aug 1999 17:14:32 GMT
X-Mailer: Mozilla 3.04 (WinNT; I)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019