Much improved MapKey function

git-svn-id: https://svn.eduke32.com/eduke32@836 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2008-07-04 01:15:32 +00:00
parent c4db75ca81
commit 2abab26c25
3 changed files with 151 additions and 159 deletions

View file

@ -152,6 +152,7 @@ void CONFIG_SetDefaultKeys(int type)
Bmemset(ud.config.KeyboardKeys, 0xff, sizeof(ud.config.KeyboardKeys)); Bmemset(ud.config.KeyboardKeys, 0xff, sizeof(ud.config.KeyboardKeys));
Bmemset(&boundkeys,0,sizeof(boundkeys)); Bmemset(&boundkeys,0,sizeof(boundkeys));
Bmemset(&mousebind,0,sizeof(mousebind));
if (type == 1) if (type == 1)
{ {
@ -333,7 +334,7 @@ void CONFIG_SetDefaults(void)
void CONFIG_ReadKeys(void) void CONFIG_ReadKeys(void)
{ {
int32 i, j; int32 i;
int32 numkeyentries; int32 numkeyentries;
int32 function; int32 function;
char keyname1[80]; char keyname1[80];
@ -373,6 +374,7 @@ void CONFIG_ReadKeys(void)
} }
ud.config.KeyboardKeys[function][0] = key1; ud.config.KeyboardKeys[function][0] = key1;
ud.config.KeyboardKeys[function][1] = key2; ud.config.KeyboardKeys[function][1] = key2;
/*
if (key1 != 0xff && keyname1[0]) if (key1 != 0xff && keyname1[0])
{ {
boundkeys[key1].repeat = 1; boundkeys[key1].repeat = 1;
@ -382,14 +384,14 @@ void CONFIG_ReadKeys(void)
if (keynames[j].name) if (keynames[j].name)
boundkeys[key1].key=Bstrdup(keynames[j].name); boundkeys[key1].key=Bstrdup(keynames[j].name);
else boundkeys[key1].key=Bstrdup(keyname1); else boundkeys[key1].key=Bstrdup(keyname1);
Bsprintf(tempbuf,"gamefunc_%s",CONFIG_FunctionNumToName(function)); Bsprintf(tempbuf,"gamefunc_%s;",CONFIG_FunctionNumToName(function));
if (!boundkeys[key1].cmd[0] || !Bstrcasecmp(tempbuf,boundkeys[key1].cmd)) if (!boundkeys[key1].cmd[0] || !Bstrcasecmp(tempbuf,boundkeys[key1].cmd))
{ {
Bstrncpy(boundkeys[key1].cmd,tempbuf, MAXBINDSTRINGLENGTH-1); Bstrncpy(boundkeys[key1].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
} }
else else
{ {
Bsprintf(tempbuf,"; gamefunc_%s",CONFIG_FunctionNumToName(function)); Bsprintf(tempbuf,"gamefunc_%s;",CONFIG_FunctionNumToName(function));
Bstrncat(boundkeys[key1].cmd,tempbuf, MAXBINDSTRINGLENGTH-1); Bstrncat(boundkeys[key1].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
} }
} }
@ -402,17 +404,18 @@ void CONFIG_ReadKeys(void)
if (keynames[j].name) if (keynames[j].name)
boundkeys[key2].key=Bstrdup(keynames[j].name); boundkeys[key2].key=Bstrdup(keynames[j].name);
else boundkeys[key2].key=Bstrdup(keyname2); else boundkeys[key2].key=Bstrdup(keyname2);
Bsprintf(tempbuf,"gamefunc_%s",CONFIG_FunctionNumToName(function)); Bsprintf(tempbuf,"gamefunc_%s;",CONFIG_FunctionNumToName(function));
if (!boundkeys[key2].cmd[0] || !Bstrcasecmp(tempbuf,boundkeys[key2].cmd)) if (!boundkeys[key2].cmd[0] || !Bstrcasecmp(tempbuf,boundkeys[key2].cmd))
{ {
Bstrncpy(boundkeys[key2].cmd,tempbuf, MAXBINDSTRINGLENGTH-1); Bstrncpy(boundkeys[key2].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
} }
else else
{ {
Bsprintf(tempbuf,"; gamefunc_%s",CONFIG_FunctionNumToName(function)); Bsprintf(tempbuf,"gamefunc_%s;",CONFIG_FunctionNumToName(function));
Bstrncat(boundkeys[key2].cmd,tempbuf, MAXBINDSTRINGLENGTH-1); Bstrncat(boundkeys[key2].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
} }
} }
*/
} }
} }
@ -425,55 +428,43 @@ void CONFIG_ReadKeys(void)
} }
} }
// wrapper for CONTROL_MapKey(), generates key bindings to reflect changes to keyboard setup
void MapKey(int32 which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2) void MapKey(int32 which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2)
{ {
int j; int i, j, k;
int ii[] = { key1, key2, oldkey1, oldkey2 };
char buf[128];
CONTROL_MapKey(which, key1, key2); CONTROL_MapKey(which, key1, key2);
if (key1 && key1 != 0xff)
for (k = 0; (unsigned)k < (sizeof(ii) / sizeof(ii[0])); k++)
{ {
boundkeys[key1].repeat = 1; if (ii[k] == 0xff || !ii[k]) continue;
for (j=0;keynames[j].name;j++) for (j=0;keynames[j].name;j++)
if (key1 == keynames[j].id) if (ii[k] == keynames[j].id)
break; break;
if (keynames[j].name) if (keynames[j].name)
boundkeys[key1].key=Bstrdup(keynames[j].name); boundkeys[ii[k]].key=Bstrdup(keynames[j].name);
Bsprintf(tempbuf,"gamefunc_%s",CONFIG_FunctionNumToName(which)); boundkeys[ii[k]].repeat = 1;
if (!boundkeys[key1].cmd[0] || !Bstrcasecmp(tempbuf,boundkeys[key1].cmd)) boundkeys[ii[k]].cmd[0] = 0;
{ tempbuf[0] = 0;
Bstrncpy(boundkeys[key1].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
}
else
{
Bsprintf(tempbuf,"; gamefunc_%s",CONFIG_FunctionNumToName(which));
Bstrncat(boundkeys[key1].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
}
}
if (key2 && key2 != 0xff)
{
boundkeys[key2].repeat = 1;
for (j=0;keynames[j].name;j++)
if (key2 == keynames[j].id)
break;
if (keynames[j].name)
boundkeys[key2].key=Bstrdup(keynames[j].name);
Bsprintf(tempbuf,"gamefunc_%s",CONFIG_FunctionNumToName(which)); for (i=0;i<NUMGAMEFUNCTIONS;i++)
if (!boundkeys[key2].cmd[0] || !Bstrcasecmp(tempbuf,boundkeys[key2].cmd))
{ {
Bstrncpy(boundkeys[key2].cmd,tempbuf, MAXBINDSTRINGLENGTH-1); if (ud.config.KeyboardKeys[i][0] == ii[k] || ud.config.KeyboardKeys[i][1] == ii[k])
} {
else Bsprintf(buf,"gamefunc_%s; ",CONFIG_FunctionNumToName(i));
{ Bstrcat(tempbuf,buf);
Bsprintf(tempbuf,"; gamefunc_%s",CONFIG_FunctionNumToName(which)); }
Bstrncat(boundkeys[key2].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
} }
Bstrncpy(boundkeys[ii[k]].cmd,tempbuf, MAXBINDSTRINGLENGTH-1);
i = Bstrlen(boundkeys[ii[k]].cmd);
if (i)
boundkeys[ii[k]].cmd[i-2] = 0; // cut off the trailing "; "
} }
if ((!key1 || key1 == 0xff) && oldkey1)
boundkeys[oldkey1].cmd[0] = 0;
if ((!key2 || key2 == 0xff) && oldkey2)
boundkeys[oldkey2].cmd[0] = 0;
} }
/* /*
@ -851,11 +842,11 @@ void CONFIG_WriteBinds(void) // save binds and aliases to disk
symbol_t *symb; symbol_t *symb;
fprintf(fp,"// this file automatically generated by EDuke32\n// do not modify if you lack common sense\n"); fprintf(fp,"// this file automatically generated by EDuke32\n// do not modify if you lack common sense\n");
for (i=0;i<MAXBOUNDKEYS;i++) for (i=0;i<MAXBOUNDKEYS;i++)
if (boundkeys[i].key && *boundkeys[i].cmd) if (boundkeys[i].cmd[0] && boundkeys[i].key)
fprintf(fp,"bind %s%s \"%s\"\n",boundkeys[i].key,boundkeys[i].repeat?"":" norepeat",boundkeys[i].cmd); fprintf(fp,"bind %s%s \"%s\"\n",boundkeys[i].key,boundkeys[i].repeat?"":" norepeat",boundkeys[i].cmd);
for (i=0;i<MAXMOUSEBUTTONS;i++) for (i=0;i<MAXMOUSEBUTTONS;i++)
if (mousebind[i].key && *mousebind[i].cmd) if (mousebind[i].cmd[0])
fprintf(fp,"bind %s%s \"%s\"\n",mousebind[i].key,mousebind[i].repeat?"":" norepeat",mousebind[i].cmd); fprintf(fp,"bind %s%s \"%s\"\n",mousebind[i].key,mousebind[i].repeat?"":" norepeat",mousebind[i].cmd);
for (symb=symbols; symb!=NULL; symb=symb->next) for (symb=symbols; symb!=NULL; symb=symb->next)

View file

@ -151,115 +151,6 @@ static char recbuf[180];
extern void computergetinput(int snum, input *syn); extern void computergetinput(int snum, input *syn);
keydef keynames[]=
{
{ "Escape", 0x1 },
{ "1", 0x2 },
{ "2", 0x3 },
{ "3", 0x4 },
{ "4", 0x5 },
{ "5", 0x6 },
{ "6", 0x7 },
{ "7", 0x8 },
{ "8", 0x9 },
{ "9", 0xa },
{ "0", 0xb },
{ "-", 0xc },
{ "=", 0xd },
{ "BakSpc", 0xe },
{ "Tab", 0xf },
{ "Q", 0x10 },
{ "W", 0x11 },
{ "E", 0x12 },
{ "R", 0x13 },
{ "T", 0x14 },
{ "Y", 0x15 },
{ "U", 0x16 },
{ "I", 0x17 },
{ "O", 0x18 },
{ "P", 0x19 },
{ "[", 0x1a },
{ "]", 0x1b },
{ "Enter", 0x1c },
{ "LCtrl", 0x1d },
{ "A", 0x1e },
{ "S", 0x1f },
{ "D", 0x20 },
{ "F", 0x21 },
{ "G", 0x22 },
{ "H", 0x23 },
{ "J", 0x24 },
{ "K", 0x25 },
{ "L", 0x26 },
{ "SemiColon", 0x27 },
{ "'", 0x28 },
{ "Tilde", 0x29 },
{ "LShift", 0x2a },
{ "\\", 0x2b },
{ "Z", 0x2c },
{ "X", 0x2d },
{ "C", 0x2e },
{ "V", 0x2f },
{ "B", 0x30 },
{ "N", 0x31 },
{ "M", 0x32 },
{ ",", 0x33 },
{ ".", 0x34 },
{ "/", 0x35 },
{ "RShift", 0x36 },
{ "Kpad*", 0x37 },
{ "LAlt", 0x38 },
{ "Space", 0x39 },
{ "CapLck", 0x3a },
{ "F1", 0x3b },
{ "F2", 0x3c },
{ "F3", 0x3d },
{ "F4", 0x3e },
{ "F5", 0x3f },
{ "F6", 0x40 },
{ "F7", 0x41 },
{ "F8", 0x42 },
{ "F9", 0x43 },
{ "F10", 0x44 },
{ "NumLck", 0x45 },
{ "ScrLck", 0x46 },
{ "Kpad7", 0x47 },
{ "Kpad8", 0x48 },
{ "Kpad9", 0x49 },
{ "Kpad-", 0x4a },
{ "Kpad4", 0x4b },
{ "Kpad5", 0x4c },
{ "Kpad6", 0x4d },
{ "Kpad+", 0x4e },
{ "Kpad1", 0x4f },
{ "Kpad2", 0x50 },
{ "Kpad3", 0x51 },
{ "Kpad0", 0x52 },
{ "Kpad.", 0x53 },
{ "F11", 0x57 },
{ "F12", 0x58 },
{ "KpdEnt", 0x9c },
{ "RCtrl", 0x9d },
{ "Kpad/", 0xb5 },
{ "RAlt", 0xb8 },
{ "PrtScn", 0xb7 },
{ "Pause", 0xc5 },
{ "Home", 0xc7 },
{ "Up", 0xc8 },
{ "PgUp", 0xc9 },
{ "Left", 0xcb },
{ "Right", 0xcd },
{ "End", 0xcf },
{ "Down", 0xd0 },
{ "PgDn", 0xd1 },
{ "Insert", 0xd2 },
{ "Delete", 0xd3 },
{0,0}
};
char *mousenames[] = { "mouse1", "mouse2", "mouse3", "mouse4", "mouse5", "mouse6" };
enum enum
{ {
T_EOF = -2, T_EOF = -2,

View file

@ -927,6 +927,115 @@ static int osdcmd_button(const osdfuncparm_t *parm)
return OSDCMD_OK; return OSDCMD_OK;
} }
keydef keynames[]=
{
{ "Escape", 0x1 },
{ "1", 0x2 },
{ "2", 0x3 },
{ "3", 0x4 },
{ "4", 0x5 },
{ "5", 0x6 },
{ "6", 0x7 },
{ "7", 0x8 },
{ "8", 0x9 },
{ "9", 0xa },
{ "0", 0xb },
{ "-", 0xc },
{ "=", 0xd },
{ "BakSpc", 0xe },
{ "Tab", 0xf },
{ "Q", 0x10 },
{ "W", 0x11 },
{ "E", 0x12 },
{ "R", 0x13 },
{ "T", 0x14 },
{ "Y", 0x15 },
{ "U", 0x16 },
{ "I", 0x17 },
{ "O", 0x18 },
{ "P", 0x19 },
{ "[", 0x1a },
{ "]", 0x1b },
{ "Enter", 0x1c },
{ "LCtrl", 0x1d },
{ "A", 0x1e },
{ "S", 0x1f },
{ "D", 0x20 },
{ "F", 0x21 },
{ "G", 0x22 },
{ "H", 0x23 },
{ "J", 0x24 },
{ "K", 0x25 },
{ "L", 0x26 },
{ "SemiColon", 0x27 },
{ "'", 0x28 },
{ "Tilde", 0x29 },
{ "LShift", 0x2a },
{ "\\", 0x2b },
{ "Z", 0x2c },
{ "X", 0x2d },
{ "C", 0x2e },
{ "V", 0x2f },
{ "B", 0x30 },
{ "N", 0x31 },
{ "M", 0x32 },
{ ",", 0x33 },
{ ".", 0x34 },
{ "/", 0x35 },
{ "RShift", 0x36 },
{ "Kpad*", 0x37 },
{ "LAlt", 0x38 },
{ "Space", 0x39 },
{ "CapLck", 0x3a },
{ "F1", 0x3b },
{ "F2", 0x3c },
{ "F3", 0x3d },
{ "F4", 0x3e },
{ "F5", 0x3f },
{ "F6", 0x40 },
{ "F7", 0x41 },
{ "F8", 0x42 },
{ "F9", 0x43 },
{ "F10", 0x44 },
{ "NumLck", 0x45 },
{ "ScrLck", 0x46 },
{ "Kpad7", 0x47 },
{ "Kpad8", 0x48 },
{ "Kpad9", 0x49 },
{ "Kpad-", 0x4a },
{ "Kpad4", 0x4b },
{ "Kpad5", 0x4c },
{ "Kpad6", 0x4d },
{ "Kpad+", 0x4e },
{ "Kpad1", 0x4f },
{ "Kpad2", 0x50 },
{ "Kpad3", 0x51 },
{ "Kpad0", 0x52 },
{ "Kpad.", 0x53 },
{ "F11", 0x57 },
{ "F12", 0x58 },
{ "KpdEnt", 0x9c },
{ "RCtrl", 0x9d },
{ "Kpad/", 0xb5 },
{ "RAlt", 0xb8 },
{ "PrtScn", 0xb7 },
{ "Pause", 0xc5 },
{ "Home", 0xc7 },
{ "Up", 0xc8 },
{ "PgUp", 0xc9 },
{ "Left", 0xcb },
{ "Right", 0xcd },
{ "End", 0xcf },
{ "Down", 0xd0 },
{ "PgDn", 0xd1 },
{ "Insert", 0xd2 },
{ "Delete", 0xd3 },
{0,0}
};
char *mousenames[] = { "mouse1", "mouse2", "mouse3", "mouse4", "mouse5", "mouse6" };
static int osdcmd_bind(const osdfuncparm_t *parm) static int osdcmd_bind(const osdfuncparm_t *parm)
{ {
int i, j; int i, j;
@ -944,16 +1053,17 @@ static int osdcmd_bind(const osdfuncparm_t *parm)
OSD_Printf("Current key bindings:\n"); OSD_Printf("Current key bindings:\n");
for (i=0;i<MAXBOUNDKEYS;i++) for (i=0;i<MAXBOUNDKEYS;i++)
if (boundkeys[i].cmd[0]) if (boundkeys[i].cmd[0] && boundkeys[i].key)
{ {
j++; j++;
OSD_Printf("%-11s = %s\n",boundkeys[i].key,boundkeys[i].cmd); OSD_Printf("%-9s %s\"%s\"\n",boundkeys[i].key, boundkeys[i].repeat?"":"norepeat ", boundkeys[i].cmd);
} }
for (i=0;i<MAXMOUSEBUTTONS;i++) for (i=0;i<MAXMOUSEBUTTONS;i++)
if (mousebind[i].cmd[0]) if (mousebind[i].cmd[0] && mousebind[i].key)
{ {
j++; j++;
OSD_Printf("%-11s = %s\n",mousebind[i].key,mousebind[i].cmd); OSD_Printf("%-9s %s\"%s\"\n",mousebind[i].key, mousebind[i].repeat?"":"norepeat ",mousebind[i].cmd);
} }
if (j == 0) if (j == 0)
@ -976,7 +1086,7 @@ static int osdcmd_bind(const osdfuncparm_t *parm)
if (parm->numparms < 2) if (parm->numparms < 2)
{ {
OSD_Printf("%-11s = %s\n",mousenames[i], mousebind[i].cmd); OSD_Printf("%-9s %s\"%s\"\n",mousenames[i], mousebind[i].repeat?"":"norepeat ",mousebind[i].cmd);
return OSDCMD_OK; return OSDCMD_OK;
} }
@ -1005,7 +1115,7 @@ static int osdcmd_bind(const osdfuncparm_t *parm)
if (parm->numparms < 2) if (parm->numparms < 2)
{ {
OSD_Printf("%-11s = %s\n",keynames[i].name, boundkeys[keynames[i].id].cmd); OSD_Printf("%-9s %s\"%s\"\n",keynames[i].name, boundkeys[keynames[i].id].repeat?"":"norepeat ", boundkeys[keynames[i].id].cmd);
return OSDCMD_OK; return OSDCMD_OK;
} }
@ -1095,7 +1205,7 @@ static int osdcmd_quickload(const osdfuncparm_t *parm)
static int osdcmd_screenshot(const osdfuncparm_t *parm) static int osdcmd_screenshot(const osdfuncparm_t *parm)
{ {
UNREFERENCED_PARAMETER(parm); UNREFERENCED_PARAMETER(parm);
KB_ClearKeysDown(); // KB_ClearKeysDown();
screencapture("duke0000.tga",0); screencapture("duke0000.tga",0);
return OSDCMD_OK; return OSDCMD_OK;
} }