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') ?
How did you declare input? Int?
ALLEGRO_USTR* format.
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 . . .
Thanks, it works!
One more question, What if I use the backspace key?
I also get the keycode into an int, i.e.
int inkey = events.keyboard.keycode; if(inkey == ALLEGRO_KEY_BACKSPACE) { blah
Of course, the last question was stupid Thanks again.
By the way, don't forget that you have to eventually free ALLEGRO_USTR* with a call to al_ustr_free()