void DumpBindings (FILE *f) { int i, leftright; char *spaces, *string; qbool printed = false; for (i = 0; i < (sizeof(keybindings) / sizeof(*keybindings)); i++) { leftright = Key_IsLeftRightSameBind(i) ? 1 : 0; if (keybindings[i] || leftright) { printed = true; #ifdef WITH_KEYMAP string = Key_KeynumToString(i, NULL); #else string = Key_KeynumToString(i); #endif spaces = CreateSpaces(BIND_ALIGN_COL - strlen(string) - 6); if (i == ';') fprintf (f, "bind \";\"%s\"%s\"\n", spaces, keybindings[i]); else fprintf (f, "bind %s%s\"%s\"\n", string, spaces, keybindings[leftright ? i + 1 : i]); if (leftright) i += 2; } } if (!printed) fprintf(f, "//no bindings\n"); }
static int IN_XBox360AxisToButton(int controllerAxis, int key, float expectedStartValue, float threshold) { unsigned int axes = 0; Sint16 axis = SDL_JoystickGetAxis(stick, controllerAxis); float f = ((float) axis) / 32767.0f; /* if(f < -in_joystickThreshold->value) { axes |= (1 << (controllerAxis * 2)); } else if(f > in_joystickThreshold->value) { axes |= (1 << ((controllerAxis * 2) + 1)); } */ if (f > (expectedStartValue + threshold + in_joystickThreshold->value)) { axes |= (1 << (controllerAxis)); } if ((axes & (1 << controllerAxis)) && !(stick_state.oldaxes & (1 << controllerAxis))) { Com_QueueEvent(0, SE_KEY, key, true, 0, nullptr); if (in_xbox360ControllerDebug->integer) { Com_Printf("xbox axis = %i to key = Q:0x%02x(%s), value = %f\n", controllerAxis, key, Key_KeynumToString(key), f); } } if (!(axes & (1 << controllerAxis)) && (stick_state.oldaxes & (1 << controllerAxis))) { Com_QueueEvent(0, SE_KEY, key, false, 0, nullptr); if (in_xbox360ControllerDebug->integer) { Com_Printf("xbox axis = %i to key = Q:0x%02x(%s), value = %f\n", controllerAxis, key, Key_KeynumToString(key), f); } } return axes; }
static void DrawKeyBindingFunc( void *self ) { int keys[2]; menuaction_s *a = ( menuaction_s * ) self; M_FindKeysForCommand( bindnames[a->generic.localdata[0]][0], keys); if (keys[0] == -1) { Menu_DrawString (a->generic.x + a->generic.parent->x + 16, a->generic.y + a->generic.parent->y, "^1<NONE>", 255); } else { int x; const char *name; int alpha; if (cursor.menuitem == a) alpha=255; else alpha=160; name = Key_KeynumToString (keys[0]); Menu_DrawString (a->generic.x + a->generic.parent->x + 16, a->generic.y + a->generic.parent->y, name , alpha); x = strlen(name) * MENU_FONT_SIZE; if (keys[1] != -1) { Menu_DrawString (a->generic.x + a->generic.parent->x + MENU_FONT_SIZE*3 + x, a->generic.y + a->generic.parent->y, "or", alpha); Menu_DrawString (a->generic.x + a->generic.parent->x + MENU_FONT_SIZE*6 + x, a->generic.y + a->generic.parent->y, Key_KeynumToString(keys[1]), alpha); } } }
/** * @brief Wrapper for UI tooltips */ void UI_Tooltip (const uiNode_t* node, int x, int y) { const char* string; const char* key = nullptr; const char* tooltip = nullptr; static const int maxWidth = 200; /* check values */ if (node->key) key = Key_KeynumToString(node->key->key); if (node->tooltip) tooltip = UI_GetReferenceString(node, node->tooltip); /* normalize */ if (tooltip && tooltip[0] == '\0') tooltip = nullptr; if (key && key[0] == '\0') key = nullptr; /* create tooltip */ if (key && tooltip) { char buf[MAX_VAR]; Com_sprintf(buf, sizeof(buf), _("Key: %s"), key); string = va("%s\n%s", tooltip, buf); } else if (tooltip) { string = tooltip; } else if (key) { string = va(_("Key: %s"), key); } else { return; } UI_DrawTooltip(string, x, y, maxWidth); }
static void Key_KeynumToStringBuf( int keynum, char *buf, int buflen ) { #else void Key_KeynumToStringBuf( int keynum, char *buf, int buflen ) { #endif // RTCW_XX Q_strncpyz( buf, Key_KeynumToString( keynum, qtrue ), buflen ); }
/* =============== IN_PrintKey =============== */ static void IN_PrintKey( const SDL_Keysym *keysym, keyNum_t key, bool down ) { if ( keysym->mod & KMOD_LSHIFT ) { Log::Notice( " KMOD_LSHIFT" ); } if ( keysym->mod & KMOD_RSHIFT ) { Log::Notice( " KMOD_RSHIFT" ); } if ( keysym->mod & KMOD_LCTRL ) { Log::Notice( " KMOD_LCTRL" ); } if ( keysym->mod & KMOD_RCTRL ) { Log::Notice( " KMOD_RCTRL" ); } if ( keysym->mod & KMOD_LALT ) { Log::Notice( " KMOD_LALT" ); } if ( keysym->mod & KMOD_RALT ) { Log::Notice( " KMOD_RALT" ); } if ( keysym->mod & KMOD_LGUI ) { Log::Notice( " KMOD_LGUI" ); } if ( keysym->mod & KMOD_RGUI ) { Log::Notice( " KMOD_RGUI" ); } if ( keysym->mod & KMOD_NUM ) { Log::Notice( " KMOD_NUM" ); } if ( keysym->mod & KMOD_CAPS ) { Log::Notice( " KMOD_CAPS" ); } if ( keysym->mod & KMOD_MODE ) { Log::Notice( " KMOD_MODE" ); } if ( keysym->mod & KMOD_RESERVED ) { Log::Notice( " KMOD_RESERVED" ); } Log::Notice( "%c 0x%02x \"%s\" Q:0x%02x(%s)\n", down ? '+' : ' ', keysym->scancode, SDL_GetKeyName( keysym->sym ), key, Key_KeynumToString( key ) ); }
/* =============== IN_PrintKey =============== */ static void IN_PrintKey( const SDL_Keysym *keysym, keyNum_t key, qboolean down ) { if( down ) Com_Printf( "+ " ); else Com_Printf( " " ); Com_Printf( "Scancode: 0x%02x(%s) Sym: 0x%02x(%s)", keysym->scancode, SDL_GetScancodeName( keysym->scancode ), keysym->sym, SDL_GetKeyName( keysym->sym ) ); if( keysym->mod & KMOD_LSHIFT ) Com_Printf( " KMOD_LSHIFT" ); if( keysym->mod & KMOD_RSHIFT ) Com_Printf( " KMOD_RSHIFT" ); if( keysym->mod & KMOD_LCTRL ) Com_Printf( " KMOD_LCTRL" ); if( keysym->mod & KMOD_RCTRL ) Com_Printf( " KMOD_RCTRL" ); if( keysym->mod & KMOD_LALT ) Com_Printf( " KMOD_LALT" ); if( keysym->mod & KMOD_RALT ) Com_Printf( " KMOD_RALT" ); if( keysym->mod & KMOD_LGUI ) Com_Printf( " KMOD_LGUI" ); if( keysym->mod & KMOD_RGUI ) Com_Printf( " KMOD_RGUI" ); if( keysym->mod & KMOD_NUM ) Com_Printf( " KMOD_NUM" ); if( keysym->mod & KMOD_CAPS ) Com_Printf( " KMOD_CAPS" ); if( keysym->mod & KMOD_MODE ) Com_Printf( " KMOD_MODE" ); if( keysym->mod & KMOD_RESERVED ) Com_Printf( " KMOD_RESERVED" ); Com_Printf( " Q:0x%02x(%s)\n", key, Key_KeynumToString( key, qtrue ) ); }
static const char *Keys_MenuKey( menuframework_s *self, int key ) { menuaction_s *item = ( menuaction_s * ) Menu_ItemAtCursor( &s_keys_menu ); if ( bind_grab ) { if ( key != K_ESCAPE && key != '`' ) { char cmd[1024]; Com_sprintf (cmd, sizeof(cmd), "bind \"%s\" \"%s\"", Key_KeynumToString(key), bindnames[item->generic.localdata[0]][0]); Cbuf_InsertText (cmd); } Menu_SetStatusBar( &s_keys_menu, "enter to change, backspace to clear" ); bind_grab = false; return menu_out_sound; } switch ( key ) { case K_KP_ENTER: case K_ENTER: case K_MOUSE1: KeyBindingFunc( item ); return menu_in_sound; case K_BACKSPACE: // delete bindings case K_DEL: // delete bindings case K_KP_DEL: M_UnbindCommand( bindnames[item->generic.localdata[0]][0] ); return menu_out_sound; default: return Default_MenuKey( self, key ); } }
static inline void CLMN_AddBindings (linkedList_t **list, char **bindings) { int i; for (i = K_FIRST_KEY; i < K_LAST_KEY; i++) if (bindings[i] && bindings[i][0] != '\0') LIST_AddString(list, va("%s\t%s", Key_KeynumToString(i), Cmd_GetCommandDesc(bindings[i]))); }
/** * @brief Called when we press a key when the node got the focus * @return True, if we use the event */ static qboolean UI_KeyBindingNodeKeyPressed (uiNode_t *node, unsigned int key, unsigned short unicode) { const char *command; const char *binding; UI_RemoveFocus(); /** @todo what about macro expansion? */ if (!Q_strstart(node->text, "*binding:")) return qfalse; command = node->text + 9; /** @todo ensure that the binding for the key command is not executed */ binding = Key_GetBinding(command, EXTRADATA(node).keySpace); if (binding[0] != '\0') { /* if it's the same command, do not change anything, otherwise * show the reason why nothing was changed */ if (!Q_streq(binding, command)) { const char *keyStr = Key_KeynumToString(key); UI_DisplayNotice(va(_("Key %s already bound"), keyStr), 2000, NULL); } return qfalse; } /* fire change event */ if (node->onChange) UI_ExecuteEventActions(node, node->onChange); Key_SetBinding(key, command, EXTRADATA(node).keySpace); return qtrue; }
/* =============== IN_PrintKey =============== */ static void IN_PrintKey( const SDL_keysym *keysym, keyNum_t key, qboolean down ) { if( down ) Com_Printf( "+ " ); else Com_Printf( " " ); Com_Printf( "0x%02x \"%s\"", keysym->scancode, SDL_GetKeyName( keysym->sym ) ); if( keysym->mod & KMOD_LSHIFT ) Com_Printf( " KMOD_LSHIFT" ); if( keysym->mod & KMOD_RSHIFT ) Com_Printf( " KMOD_RSHIFT" ); if( keysym->mod & KMOD_LCTRL ) Com_Printf( " KMOD_LCTRL" ); if( keysym->mod & KMOD_RCTRL ) Com_Printf( " KMOD_RCTRL" ); if( keysym->mod & KMOD_LALT ) Com_Printf( " KMOD_LALT" ); if( keysym->mod & KMOD_RALT ) Com_Printf( " KMOD_RALT" ); if( keysym->mod & KMOD_LMETA ) Com_Printf( " KMOD_LMETA" ); if( keysym->mod & KMOD_RMETA ) Com_Printf( " KMOD_RMETA" ); if( keysym->mod & KMOD_NUM ) Com_Printf( " KMOD_NUM" ); if( keysym->mod & KMOD_CAPS ) Com_Printf( " KMOD_CAPS" ); if( keysym->mod & KMOD_MODE ) Com_Printf( " KMOD_MODE" ); if( keysym->mod & KMOD_RESERVED ) Com_Printf( " KMOD_RESERVED" ); Com_Printf( " Q:0x%02x(%s)", key, Key_KeynumToString( key ) ); if( keysym->unicode ) { Com_Printf( " U:0x%02x", keysym->unicode ); if( keysym->unicode > ' ' && keysym->unicode < '~' ) Com_Printf( "(%c)", (char)keysym->unicode ); } Com_Printf( "\n" ); }
static void DrawKeyBindingFunc( void *self ) { int mkeys[2]; menuaction_s *a = ( menuaction_s * ) self; M_FindKeysForCommand( bindnames[a->generic.localdata[0]][0], mkeys); if (mkeys[0] == -1) { Menu_DrawString( a->generic.x + a->generic.parent->x + 16, a->generic.y + a->generic.parent->y, "???" ); } else { int x; const char *name; name = Key_KeynumToString (mkeys[0]); Menu_DrawString( a->generic.x + a->generic.parent->x + 16, a->generic.y + a->generic.parent->y, name ); x = strlen(name) * 8; if (mkeys[1] != -1) { Menu_DrawString( a->generic.x + a->generic.parent->x + 24 + x, a->generic.y + a->generic.parent->y, "or" ); Menu_DrawString( a->generic.x + a->generic.parent->x + 48 + x, a->generic.y + a->generic.parent->y, Key_KeynumToString (mkeys[1]) ); } } }
/* ============ Cmd_JoyRemapList_f ============ */ void Cmd_JoyRemapList_f( void ) { int i; int localPlayerNum; joyDevice_t *device; localPlayerNum = Com_LocalPlayerForCvarName( Cmd_Argv(0) ); if ( playerJoyRemapIndex[ localPlayerNum ] == -1 ) { Com_Printf( "Joystick for player %d not initialized\n", localPlayerNum+1 ); return; } device = &joyDevice[ playerJoyRemapIndex[ localPlayerNum ] ]; if ( strcmp( device->name, device->ident ) ) { Com_Printf("Device: %s (%s)\n", device->name, device->ident ); } else { Com_Printf("Device: %s\n", device->name ); } for ( i = 0 ; i < MAX_JOY_REMAPS ; i++ ) { if ( device->remap[i].event.type == JOYEVENT_NONE ) { continue; } Com_Printf ("%s %s\n", CL_JoyEventToString( &device->remap[i].event ), Key_KeynumToString( device->remap[i].keynum ) ); } }
/** * @brief Return the key binding for a given script command * @param[in] binding The script command to bind keynum to * @param space Namespace of the key binding * @sa Key_SetBinding * @return the binded key or empty string if not found */ const char* Key_GetBinding (const char *binding, keyBindSpace_t space) { int i; char **keySpace = NULL; switch (space) { case KEYSPACE_UI: keySpace = menuKeyBindings; break; case KEYSPACE_GAME: keySpace = keyBindings; break; case KEYSPACE_BATTLE: keySpace = battleKeyBindings; break; default: Sys_Error("Unknown key space (%i) given", space); } for (i = K_FIRST_KEY; i < K_LAST_KEY; i++) if (keySpace[i] && *keySpace[i] && Q_streq(keySpace[i], binding)) { return Key_KeynumToString(i); } /* not found */ return ""; }
//string keynumtostring(float keynum) = #609; void QCBUILTIN PF_cl_keynumtostring (pubprogfuncs_t *prinst, struct globalvars_s *pr_globals) { int code = G_FLOAT(OFS_PARM0); code = MP_TranslateQCtoFTECodes (code); RETURN_TSTRING(Key_KeynumToString(code, 0)); }
/* * Key_Bindlist_f */ static void Key_Bindlist_f( void ) { int i; for( i = 0; i < 256; i++ ) if( keybindings[i] && keybindings[i][0] ) Com_Printf( "%s \"%s\"\n", Key_KeynumToString( i ), keybindings[i] ); }
/* ============ Key_WriteBindings Writes lines containing "bind key value" ============ */ void Key_WriteBindings (FILE *f) { int i; for (i=0 ; i<256 ; i++) if (keybindings[i] && keybindings[i][0]) fprintf (f, "bind %s \"%s\"\n", Key_KeynumToString(i), keybindings[i]); }
/** * @brief List all binded keys with its function */ static void Key_Bindlist_f (void) { int i; Com_Printf("key space: game\n"); for (i = K_FIRST_KEY; i < K_LAST_KEY; i++) if (keyBindings[i] && keyBindings[i][0]) Com_Printf("- %s \"%s\"\n", Key_KeynumToString(i), keyBindings[i]); Com_Printf("key space: menu\n"); for (i = K_FIRST_KEY; i < K_LAST_KEY; i++) if (menuKeyBindings[i] && menuKeyBindings[i][0]) Com_Printf("- %s \"%s\"\n", Key_KeynumToString(i), menuKeyBindings[i]); Com_Printf("key space: battle\n"); for (i = 0; i < K_LAST_KEY; i++) if (battleKeyBindings[i] && battleKeyBindings[i][0]) Com_Printf("- %s \"%s\"\n", Key_KeynumToString(i), battleKeyBindings[i]); }
/* * @brief Prints keyboard identifiers in the console */ static void IN_PrintKey(const SDL_Keysym *keysym, keyNum_t key, qboolean down) { if (down) { Com_Printf("+ "); } else { Com_Printf(" "); } Com_Printf("0x%02x \"%s\"", keysym->scancode, SDL_GetKeyName(keysym->sym)); if (keysym->mod & KMOD_LSHIFT) { Com_Printf(" KMOD_LSHIFT"); } if (keysym->mod & KMOD_RSHIFT) { Com_Printf(" KMOD_RSHIFT"); } if (keysym->mod & KMOD_LCTRL) { Com_Printf(" KMOD_LCTRL"); } if (keysym->mod & KMOD_RCTRL) { Com_Printf(" KMOD_RCTRL"); } if (keysym->mod & KMOD_LALT) { Com_Printf(" KMOD_LALT"); } if (keysym->mod & KMOD_RALT) { Com_Printf(" KMOD_RALT"); } if (keysym->mod & KMOD_NUM) { Com_Printf(" KMOD_NUM"); } if (keysym->mod & KMOD_CAPS) { Com_Printf(" KMOD_CAPS"); } if (keysym->mod & KMOD_MODE) { Com_Printf(" KMOD_MODE"); } if (keysym->mod & KMOD_RESERVED) { Com_Printf(" KMOD_RESERVED"); } Com_Printf(" Q:0x%02x(%s)\n", key, Key_KeynumToString(key,qtrue)); }
// only ever called by binding-display code, therefore returns non-technical "friendly" names // in any language that don't necessarily match those in the config file... // void Key_KeynumToStringBuf( int keynum, char *buf, int buflen ) { const char *psKeyName = Key_KeynumToString( keynum/*, qtrue */); // see if there's a more friendly (or localised) name... // const char *psKeyNameFriendly = SE_GetString( va("KEYNAMES_KEYNAME_%s",psKeyName) ); Q_strncpyz( buf, (psKeyNameFriendly && psKeyNameFriendly[0]) ? psKeyNameFriendly : psKeyName, buflen ); }
/* ============ Key_Bindlist_f ============ */ void Key_Bindlist_f( void ) { int i; for( i = 0; i < 256; i++ ) { if( keys[i].binding && keys[i].binding[0] ) Msg( "%s \"%s\"\n", Key_KeynumToString( i ), keys[i].binding ); } }
/* * Key_WriteBindings * * Writes lines containing "bind key value" */ void Key_WriteBindings( int file ) { int i; FS_Printf( file, "unbindall\r\n" ); for( i = 0; i < 256; i++ ) if( keybindings[i] && keybindings[i][0] ) FS_Printf( file, "bind %s \"%s\"\r\n", (i == ';' ? SEMICOLON_BINDNAME : Key_KeynumToString( i )), keybindings[i] ); }
/* ============ Key_WriteBindings Writes lines containing "bind key value" ============ */ void Key_WriteBindings(qhandle_t f) { int i; for (i = 0; i < 256; i++) { if (keybindings[i] && keybindings[i][0]) { FS_FPrintf(f, "bind %s \"%s\"\n", Key_KeynumToString(i), keybindings[i]); } } }
/* ============ Key_WriteBindings Writes lines containing "bind key value" ============ */ void Key_WriteBindings( fileHandle_t f ) { int i; FS_Printf( f, "unbindall" Q_NEWLINE ); for ( i = 0 ; i < MAX_KEYS ; i++ ) { if ( keys[i].binding && keys[i].binding[0] ) { FS_Printf( f, "bind %s \"%s\"" Q_NEWLINE, Key_KeynumToString(i), keys[i].binding ); } } }
/* ============ Key_Bindlist_f ============ */ void Key_Bindlist_f( void ) { int i; Sys_BeginPrint(); for ( i = 0 ; i < MAX_KEYS ; i++ ) { if ( keys[i].binding && keys[i].binding[0] ) { Com_Printf( "%s \"%s\"\n", Key_KeynumToString(i), keys[i].binding ); } } Sys_EndPrint(); }
void IN_EventEnqueue (unsigned int keyNum, unsigned short keyUnicode, qboolean keyDown) { if (keyNum > 0 || keyUnicode > 0) { if (in_debug->integer) Com_Printf("Enqueue: %s (%i) (down: %i)\n", Key_KeynumToString(keyNum), keyNum, keyDown); keyq[keyq_head].down = keyDown; keyq[keyq_head].unicode = keyUnicode; keyq[keyq_head].key = keyNum; keyq_head = (keyq_head + 1) & (MAX_KEYQ - 1); } }
static inline void CLMN_AddBindings (linkedList_t **list, char **bindings) { int i; for (i = K_FIRST_KEY; i < K_LAST_KEY; i++) if (bindings[i] && bindings[i][0] != '\0') { const char *binding = Cmd_GetCommandDesc(bindings[i]); if (binding != NULL && binding[0] != '\0') binding = _(binding); LIST_AddString(list, va("%s\t%s", Key_KeynumToString(i), binding)); } }
static inline void CLMN_AddBindings (keyBindSpace_t scope, char** bindings, int offset = 0) { for (int i = K_FIRST_KEY; i < K_LAST_KEY; i++) { if (Q_strnull(bindings[i])) continue; const char* binding = Cmd_GetCommandDesc(bindings[i]); if (Q_strvalid(binding)) binding = _(binding); UI_ExecuteConfunc("keybinding_add %i %i \"%s\" \"%s\"", i + offset, scope, Key_KeynumToString(i), binding); } }
/** * \brief Console callback method to print bindlist */ PRIVATE void Key_Bindlist_f( void ) { int i; for( i = 0 ; i < 256 ; ++i ) { if( keybindings[ i ] && keybindings[ i ][ 0 ] ) { Com_Printf( "%s \"%s\"\n", Key_KeynumToString( i ), keybindings[ i ] ); } } }
/* ============ Key_WriteBindings Writes lines containing "bind key value" ============ */ void Key_WriteBindings( file_t *f ) { int i; if( !f ) return; FS_Printf( f, "unbindall\n" ); for( i = 0; i < 256; i++ ) { if( keys[i].binding && keys[i].binding[0] ) FS_Printf( f, "bind %s \"%s\"\n", Key_KeynumToString(i), keys[i].binding ); } }