delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/09/15:31:14

From: malcolmj7 AT aol DOT com (MalcolmJ7)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro: Keyboard question...
Lines: 59
Message-ID: <1998060919181900.PAA01515@ladder01.news.aol.com>
NNTP-Posting-Host: ladder01.news.aol.com
Date: 09 Jun 1998 19:18:19 GMT
Organization: AOL http://www.aol.com
References: <357D268E DOT 82CD8D70 AT netrover DOT com>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

you have to make a function yourself using textout, and readkey.  
Here is an example:


#include "allegro.h"

int get_input(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++)
  {
  strings[index] = NULL;
  }
index = 0;
simulate_keypress(32);
while (!key[KEY_ENTER])
  {
  keys = readkey() & 0xff;
  if (key[KEY_BACKSPACE])
   {
   index --;
   strings[index] = '\0';
   bs = 1;
   }
  strings[index] = keys;
  if (!bs)
   index++;
  textprintf(screen,font,x,y,c, "%s",strings);
  if (index == length)
   {
   break;
   }
  bs = 0;
  }
  strcpy(string,strings);
  return 1;
  }

int main()
 {
 char *the_text;
 allegro_init();
 install_keyboard();
 set_gfx_mode(GFX_AUTODETECT,320,200,0,0);
 textprintf(screen,font,8,8,15,"enter your name");
 get_input(the_text,15,17*8,8,4);
 textprintf(screen,font,20,90,15,the_text);
 while (!keypressed())
  {};
 remove_keyboard();
 set_gfx_mode(GFX_TEXT,0,0,0,0);
 }


Its, not optimized, but i just wrote it last night
Malcolm
malcolmj7 AT aol DOT com

- Raw text -


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