Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Converting allegro_key_xxx to the same character

This thread is locked; no one can reply to it. rss feed Print
Converting allegro_key_xxx to the same character
Gnamra
Member #12,503
January 2011
avatar

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
Member #7,827
October 2006
avatar

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

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Gnamra
Member #12,503
January 2011
avatar

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.

Go to: