delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/10/13:06:27

From: Nicolas Blais <eletech AT netrover DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Allegro: Keyboard question...
Date: Wed, 10 Jun 1998 07:58:30 -0400
Organization: Elemental Technologies
Lines: 68
Message-ID: <357E74E6.2F0AA07C@netrover.com>
References: <357D268E DOT 82CD8D70 AT netrover DOT com> <1998060919181900 DOT PAA01515 AT ladder01 DOT news DOT aol DOT com>
NNTP-Posting-Host: 198.168.87.55
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Isn't there a similar smaller function using strcpy() etc...?
Also, when I try your function below, it gives me a error after about 15
characters, why?

Nicolas Blais

MalcolmJ7 wrote:

> 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