|
Editors note: this is not a complete tutorial, but taken from a forum post on this subject. If anyone feels the need to comment/describe the code some further, feel free to send in improvements to tutorials@quakesrc.org
Here is my code for managing international keyboard. in qcommon/common.c 1/ Search the code : void Key_Init (void); Then add : void KeyTrans_Init (void); 2/ Search the code :
SV_Init () ;
CL_Init () ;
Then add :
KeyTrans_Init() ;
in client/key.c 3/ Search the code : int shift_down=false; Then add : int alt_down=false; int ctrl_down=false; 4/ Search the code :
{"SEMICOLON", ';'}, // because a raw semicolon seperates commands
{NULL,0}
};
Then add :
//-----------------------------------------------------------------------------
// Load a file for translation of key code for international keyboard
// If the file doesn't exist, create it with internal values
//-----------------------------------------------------------------------------
#define SIZE_KEY_TRANSTAB ('~'-' ')
static char KeyTransTab[SIZE_KEY_TRANSTAB+1]; // key to map
static char KeyTransTab_altgr[SIZE_KEY_TRANSTAB+1];
static qboolean l_bKeyTrans = false ;
//-----------------------------------------------------------------------------
void KeyTrans_Init (void)
{
unsigned char *pStr;
char *keytrans;
char *pbuf;
int i;
keytrans = Cvar_VariableString ("keytrans") ;
if ( *keytrans )
{
FS_LoadFile(keytrans, &pbuf) ;
if ( pbuf )
{
pStr = strtok(pbuf, "\n\r") ;
if ( strlen(pStr) >= SIZE_KEY_TRANSTAB )
{
memcpy(KeyTransTab, pStr, SIZE_KEY_TRANSTAB) ;
pStr = strtok(NULL, "\n\r") ;
if ( strlen(pStr) >= SIZE_KEY_TRANSTAB )
{
for ( i=0 ; i5/ Search the code :
void Key_Event (int key, qboolean down, unsigned time)
{
char *kb;
char cmd[1024];
// hack for modal presses
if (key_waiting == -1)
{
if (down)
key_waiting = key;
return;
}
Then add :
if ( l_bKeyTrans )
KeyTrans(&key, down, time) ;
6/ Search the code :
if (key == K_SHIFT)
shift_down = down;
Then add :
else if (key == K_ALT)
alt_down = down;
else if (key == K_CTRL)
ctrl_down = down;
Compile your project and run it with '+set keytrans qwerty.txt' in the
command line. The first time, it will create a file with the default
state of the keys. You can copy the file in 'yourfile.txt' and modify
it. The file contain 3 lines : symbol corresponding to keys, keys + I have already done the file azerty.txt for french keyboard. |