DISCLAIMER: I have never used this library!
I found this:
Any other (printable) key :
TCODK_CHAR
So when you receive TCODK_CHAR
, you look for char c;
from this struct:
typedef struct {
TCOD_keycode_t vk;
char c;
unsigned pressed : 1;
unsigned lalt : 1;
unsigned lctrl : 1;
unsigned ralt : 1;
unsigned rctrl : 1;
unsigned shift : 1;
} TCOD_key_t;
I believe it will contain character pressed.
UPDATE
It's a C library, so intended usage is probably was something like:
(key
here is of type TCOD_key_t
)
switch(key.vk) {
case TCODK_UP : onUp(); break;
case TCODK_CHAR: onChar(key.c); break
default: break;
}
With map you could do something like:
if(TCODK_CHAR == key.vk)
onChar(key.c);
else
specialCommands[key.vk]();
(where
specialCommands
is std::map<TCOD_keycode_t, std::function<...> >
)
You might put char
callbacks tinto the map, however, if some of the members of TCOD_keycode_t
enumeration will match character code, you will have a key collision (i.e. if, hypothetically TCODK_UP
has value 65
, it will be the same key as char 'a'
(ASCII code 65
)).
You could also have another map
or array
that maps characters (key.c
) to different functions.