ftp.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/06/27/06:15:32

Xref: news-dnh.mv.net comp.os.msdos.djgpp:620
Newsgroups: comp.os.msdos.djgpp
Path: news-dnh.mv.net!mv!news.sprintlink.net!cs.utexas.edu!utnut!nott!cunews!freenet.carleton.ca!FreeNet.Carleton.CA!ao950
From: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire)
Subject: Re: Problem with keyboard handling
Sender: ao950 AT freenet2 DOT carleton DOT ca (Paul Derbyshire)
Reply-To: ao950 AT FreeNet DOT Carleton DOT CA (Paul Derbyshire)
Organization: The National Capital FreeNet
References: <DArs22 DOT 3MK AT jade DOT mv DOT net>
Date: Tue, 27 Jun 1995 03:58:03 GMT
Lines: 39
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Dj-Gateway: from newsgroup comp.os.msdos.djgpp


I use this all the time and it works:

char ch;
if (kbhit()!=0) {
  /* Key hit, read it with getch() and handle it */
  ch=getch();
  switch (ch) {
  case whatever:
    whatever;
    break;
  .
  .
  .
  case 0:
    /* Extended key such as arrow keys */
    ch=getch();		/* get extended keycode */
    switch (ch) {
    case whatever:
      whatever;
      break;
    .
    .
    .
  }
}

These extended codes result from there being more than 256 keys (counting
shifted keys, etc.) and chars only holding up to 256. If an extended key
is hit (arrow key for instance) TWO characters go onto the getch() queue.
The first is a 0 (not '0'=48, an actual null) and the second is an
extended code. You should be able to find a table of these extended codes
somewhere.
--
    .*.  "Clouds are not spheres, mountains are not cones, coastlines are not
 -()  <  circles, and bark is not smooth, nor does lightning travel in a
    `*'  straight line."    ,------------------------------------------------
         -- B. Mandelbrot  |  Paul Derbyshire (PGD) ao950 AT freenet DOT carleton DOT ca

- Raw text -


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