void C_DoBind (const char *key, const char *bind, bool dodouble) { int keynum = GetKeyFromName (key); if (keynum == 0) { if (stricmp (key, "LeftBracket") == 0) { keynum = GetKeyFromName ("["); } else if (stricmp (key, "RightBracket") == 0) { keynum = GetKeyFromName ("]"); } else if (stricmp (key, "Equals") == 0) { keynum = GetKeyFromName ("="); } else if (stricmp (key, "KP-Equals") == 0) { keynum = GetKeyFromName ("kp="); } } if (keynum != 0) { (dodouble ? DoubleBindings : Bindings)[keynum] = bind; } }
// // C_DoNetDemoKey // // [SL] 2012-03-29 - Handles the hard-coded key bindings used during // NetDemo playback. Returns false if the key pressed is not // bound to any netdemo command. // bool C_DoNetDemoKey (event_t *ev) { if (!netdemo.isPlaying() && !netdemo.isPaused()) return false; static bool initialized = false; if (!initialized) { NetDemoBindings[GetKeyFromName("leftarrow")] = "netrew"; NetDemoBindings[GetKeyFromName("rightarrow")] = "netff"; NetDemoBindings[GetKeyFromName("uparrow")] = "netprevmap"; NetDemoBindings[GetKeyFromName("downarrow")] = "netnextmap"; NetDemoBindings[GetKeyFromName("space")] = "netpause"; initialized = true; } if (ev->type != ev_keydown && ev->type != ev_keyup) return false; std::string *binding = &NetDemoBindings[ev->data1]; // nothing bound to this key specific to netdemos? if (binding->empty()) return false; if (ev->type == ev_keydown) AddCommandString(binding->c_str()); return true; }
void FKeyBindings::PerformBind(FCommandLine &argv, const char *msg) { int i; if (argv.argc() > 1) { i = GetKeyFromName (argv[1]); if (!i) { Printf ("Unknown key \"%s\"\n", argv[1]); return; } if (argv.argc() == 2) { Printf ("\"%s\" = \"%s\"\n", argv[1], Binds[i].GetChars()); } else { Binds[i] = argv[2]; } } else { Printf ("%s:\n", msg); for (i = 0; i < NUM_KEYS; i++) { if (!Binds[i].IsEmpty()) Printf ("%s \"%s\"\n", KeyName (i), Binds[i].GetChars()); } } }
void FKeyBindings::UnbindKey(const char *key) { int i; if ( (i = GetKeyFromName (key)) ) { Binds[i] = ""; } else { Printf ("Unknown key \"%s\"\n", key); return; } }
static int GetConfigKeyFromName (const char *key) { int keynum = GetKeyFromName(key); if (keynum == 0) { if (stricmp (key, "LeftBracket") == 0) { keynum = GetKeyFromName ("["); } else if (stricmp (key, "RightBracket") == 0) { keynum = GetKeyFromName ("]"); } else if (stricmp (key, "Equals") == 0) { keynum = GetKeyFromName ("="); } else if (stricmp (key, "KP-Equals") == 0) { keynum = GetKeyFromName ("kp="); } } return keynum; }
void FKeyBindings::DefaultBind(const char *keyname, const char *cmd) { int key = GetKeyFromName (keyname); if (key == 0) { Printf ("Unknown key \"%s\"\n", keyname); return; } if (!Binds[key].IsEmpty()) { // This key is already bound. return; } for (int i = 0; i < NUM_KEYS; ++i) { if (!Binds[i].IsEmpty() && stricmp (Binds[i], cmd) == 0) { // This command is already bound to a key. return; } } // It is safe to do the bind, so do it. Binds[key] = cmd; }