int
Key_StringToKeynum (const char *str)
{
+ Uchar ch;
const keyname_t *kn;
if (!str || !str[0])
if (!strcasecmp (str, kn->name))
return kn->keynum;
}
- return -1;
+
+ // non-ascii keys are Unicode codepoints, so give the character
+ ch = u8_getnchar(str, &str, 3);
+ return ch == 0 ? -1 : (int)ch;
}
/*
return kn->name;
// if it is printable, output it as a single character
- if (keynum > 32 && keynum < 256)
+ if (keynum > 32)
{
- if (tinystrlength >= 2)
- {
- tinystr[0] = keynum;
- tinystr[1] = 0;
- }
+ u8_fromchar(keynum, tinystr, tinystrlength);
return tinystr;
}
Key_PrintBindList(int j)
{
char bindbuf[MAX_INPUTLINE];
- char tinystr[2];
+ char tinystr[TINYSTR_LEN];
const char *p;
int i;
{
int i, j;
char bindbuf[MAX_INPUTLINE];
- char tinystr[2];
+ char tinystr[TINYSTR_LEN];
const char *p;
// Override default binds
#include "fs.h"
#include "cmd.h"
+// the highest Unicode character to allow key binding.
+// note that an excessively high value may degrade fps
+// when code is looping through the bindings
+#define MAX_KEY_BINDS 0xfff0
+
+// how long is a "tinystr" to hold a keyboard key's
+// Unicode utf-8 presentation, plus final \x00
+// to allow all characters <= 0xffff, use 4
+#define TINYSTR_LEN 4
+
//
// these are the key numbers that should be passed to Key_Event
//
K_MIDINOTE126,
K_MIDINOTE127,
- MAX_KEYS
+ MAX_KEYS = MAX_KEY_BINDS
}
keynum_t;
strlcpy(keystring, "???", sizeof(keystring));
else
{
- char tinystr[2];
+ char tinystr[TINYSTR_LEN];
keystring[0] = 0;
for (j = 0;j < NUMKEYS;j++)
{
{
char line[80];
int keys[NUMKEYS];
- char tinystr[2];
+ char tinystr[TINYSTR_LEN];
if (bind_grab)
{ // defining a key
*/
void VM_keynumtostring (prvm_prog_t *prog)
{
- char tinystr[2];
+ char tinystr[TINYSTR_LEN];
VM_SAFEPARMCOUNT(1, VM_keynumtostring);
PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, Key_KeynumToString((int)PRVM_G_FLOAT(OFS_PARM0), tinystr, sizeof(tinystr)));
{
switch(sdlkey)
{
- default: return 0;
+ // sdlkey can be Unicode codepoint for non-ascii keys, which are valid
+ default: return sdlkey;
// case SDLK_UNKNOWN: return K_UNKNOWN;
case SDLK_RETURN: return K_ENTER;
case SDLK_ESCAPE: return K_ESCAPE;
static qbool sound_active = true;
int keycode;
int i;
+ const char *chp;
qbool isdown;
Uchar unicode;
SDL_Event event;
#endif
// convert utf8 string to char
// NOTE: this code is supposed to run even if utf8enable is 0
- unicode = u8_getchar_utf8_enabled(event.text.text + (int)u8_bytelen(event.text.text, 0), NULL);
- Key_Event(K_TEXT, unicode, true);
- Key_Event(K_TEXT, unicode, false);
+ chp = event.text.text;
+ while (*chp != 0)
+ {
+ // input the chars one by one (there can be multiple chars when e.g. using an "input method")
+ unicode = u8_getchar_utf8_enabled(chp, &chp);
+ Key_Event(K_TEXT, unicode, true);
+ Key_Event(K_TEXT, unicode, false);
+ }
break;
case SDL_MOUSEMOTION:
break;