delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/19/02:30:38

From: George Foot <mert0407 AT sable DOT ox DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: String input using Allegro
Date: 19 Jun 1998 05:17:25 GMT
Organization: Oxford University, England
Lines: 43
Message-ID: <6mcs95$loc$2@news.ox.ac.uk>
References: <3589A771 DOT 431CC375 AT netrover DOT com> <1998061901305700 DOT VAA12138 AT ladder01 DOT news DOT aol DOT com>
NNTP-Posting-Host: sable.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On 19 Jun 1998 01:30:57 GMT in comp.os.msdos.djgpp MalcolmJ7
<malcolmj7 AT aol DOT com> wrote:

: int get_input (FONT *tfont, char *string,int length,int x,int y,int c)
: {
:  char strings[length];
:  int index,bs;
:  int keys;
: for (index = 0;index <length +1;index++)
:   {
:   string[index] = NULL;
:   }
: index = 0;
: simulate_keypress(32);
: while (!key[KEY_ENTER])
:   {
:   keys = readkey() & 0xff;
:   if (key[KEY_BACKSPACE])
...

Mixing `readkey' calls with tests on the `key' array may not do what
you expect it to.  The `key' array tests whether a key is currently
depressed, at the time of the read from the array.  The `readkey'
function operates from a buffer, and may return keys which were
pressed some time ago.  Also note that you can hold down the Backspace
(which means key[KEY_BACKSPACE] is nonzero) and press another key.
`readkey' will pick up the other key, after a few backspaces, but
because key[BACKSPACE] is still pressed your code will act wrongly.

A better way to do this is to remove references to `key' and use the
high byte returned from `readkey' to determine the scancode of the key
that was pressed.  Alternatively (and perhaps better) you could stick
to using the low byte, and not use scancodes at all.  Note that
scancodes of keys vary between keyboard layouts, especially between
countries. 

Incidentally, a simple way to read strings from the keyboard is to use
the GUI routines to display a dialog box containing a text edit box.

-- 
george DOT foot AT merton DOT oxford DOT ac DOT uk

xu do tavla fo la lojban  --  http://xiron.pc.helsinki.fi/lojban/lojban.html

- Raw text -


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