Mail Archives: djgpp/1998/06/19/02:30:38
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 -