Converting allegro_key_xxx to the same character
Gnamra

I've usually only used the keys I've needed in my projects so far, but right now I'm working on a project with chatting, so needless to say I've got to support all keys. I do want to support multiple languages, can I use allegro for this? Or would it be easier to use a different library for this?

SiegeLord

Allegro 5 has ALLEGRO_EVENT_KEY_CHAR for this. Check the unichar field.

Gnamra

Oh, thanks :D

edit:
converting the unichar field to char works fine for the english characters. But not special characters like "æ ø å". I've been trying to figure out the ALLEGRO_USTR, but it's a bit confusing. I can't a tutorial on it on the wiki either. The documentation did help me understand UTF-8, I'll probably start using it all the time once I figure out how to work with it.

I assume I can use the event.keyboard.unichar with the ALLEGRO_USTR? I've tried doing:

ALLEGRO_USTR *input = al_ustr_new("");
...
...
input += ev.keyboard.unichar
...
...
al_draw_textf(font, al_map_rgb(255,0,0), 10, 30, 0, "%s", input);

it didn't work, so it's obviously wrong. I also tried using al_ustr_append_chr(input, ev.keyboard.unichar);

second edit:
it worked if I did

ALLEGRO_USTR *input = al_ustr_new("");
...
...
al_ustr_append_chr(input, ev.keyboard.unichar);
...
...
al_draw_textf(font, al_map_rgb(255,0,0), 10, 30, 0, "%s", al_cstr(u));

I dunno why I thought the textf function would work with a ALLEGRO_USTR.

Thread #612163. Printed from Allegro.cc