Allegro 5 User Input
ma3stro

I have these lines in my project:

ALLEGRO_USTR *input= al_ustr_new("");
int pos = (int)al_ustr_size(input);

.
.
.

if(events.keyboard.unichar >= 32)
{
pos += al_ustr_append_chr(input, events.keyboard.unichar);
}
else if(events.keyboard.keycode == ALLEGRO_KEY_BACKSPACE)
{ if(al_ustr_prev(input, &pos))
al_ustr_truncate(input, pos);
}

.
.
.

and here, I want to test the input with an if statement but I am not allowed to compare ALLEGRO_USTR format with char* or int.

How can I make something like this work : if(input == '3') ?

Arthur Kalliokoski

How did you declare input? Int?

ma3stro

ALLEGRO_USTR* format.

Arthur Kalliokoski

Aw crap, I just woke up and didn't see it in the original post.

I'd think this would work

int inchar = events.keyboard.unichar;
if(inchar >= 32)
{
  pos += al_ustr_append_chr(input, inchar);
  blah
  blah
  if(inchar == '3')
  {
    blah
     .
     .
     .

ma3stro

Thanks, it works!

One more question, What if I use the backspace key?

Arthur Kalliokoski

I also get the keycode into an int, i.e.

int inkey = events.keyboard.keycode;
if(inkey == ALLEGRO_KEY_BACKSPACE)
{
  blah

ma3stro

Of course, the last question was stupid :) Thanks again.

Aikei_c

By the way, don't forget that you have to eventually free ALLEGRO_USTR* with a call to al_ustr_free()

Thread #613380. Printed from Allegro.cc