Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Allegro 5 User Input

This thread is locked; no one can reply to it. rss feed Print
Allegro 5 User Input
ma3stro
Member #15,329
October 2013

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
Second in Command
February 2005
avatar

How did you declare input? Int?

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

ma3stro
Member #15,329
October 2013

ALLEGRO_USTR* format.

Arthur Kalliokoski
Second in Command
February 2005
avatar

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
     .
     .
     .

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

ma3stro
Member #15,329
October 2013

Thanks, it works!

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

Arthur Kalliokoski
Second in Command
February 2005
avatar

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

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

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

ma3stro
Member #15,329
October 2013

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

Aikei_c
Member #14,871
January 2013
avatar

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

Go to: