Skip to content

Commit

Permalink
Hotkeys: Support more keybindings (#6719)
Browse files Browse the repository at this point in the history
* Extend F keys with F13-F24 range
* Add more possible keybindings
* Removed hardcoded keys that are used elsewhere
* Put PAUSE back where it was before
* Remove hardcoded logic for PAUSE key
* Hotkeys: Support more keybindings

This patch adds more keybindings, so we can map multiple keys.

It also adds a possibility to bind an alternate key to pause game
(currently mapped to P and Pause key by default).

Co-authored-by: n <[email protected]>
Co-authored-by: staphen <[email protected]>
  • Loading branch information
3 people authored Oct 17, 2023
1 parent 3ac2f05 commit 9123f01
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
10 changes: 6 additions & 4 deletions Source/diablo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,6 @@ void PressKey(SDL_Keycode vkey, uint16_t modState)
if (vkey == SDLK_UNKNOWN)
return;

if (vkey == SDLK_PAUSE) {
diablo_pause_game();
return;
}
if (gmenu_presskeys(vkey) || control_presskeys(vkey)) {
return;
}
Expand Down Expand Up @@ -1821,6 +1817,12 @@ void InitKeymapActions()
N_("Pauses the game."),
'P',
diablo_pause_game);
sgOptions.Keymapper.AddAction(
"Pause Game (Alternate)",
N_("Pause Game (Alternate)"),
N_("Pauses the game."),
SDLK_PAUSE,
diablo_pause_game);
sgOptions.Keymapper.AddAction(
"DecreaseGamma",
N_("Decrease Gamma"),
Expand Down
31 changes: 30 additions & 1 deletion Source/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ std::vector<OptionEntryBase *> LanguageOptions::GetEntries()
KeymapperOptions::KeymapperOptions()
: OptionCategoryBase("Keymapping", N_("Keymapping"), N_("Keymapping Settings"))
{
// Insert all supported keys: a-z, 0-9 and F1-F12.
// Insert all supported keys: a-z, 0-9 and F1-F24.
keyIDToKeyName.reserve(('Z' - 'A' + 1) + ('9' - '0' + 1) + 12);
for (char c = 'A'; c <= 'Z'; ++c) {
keyIDToKeyName.emplace(c, std::string(1, c));
Expand All @@ -1303,6 +1303,9 @@ KeymapperOptions::KeymapperOptions()
for (int i = 0; i < 12; ++i) {
keyIDToKeyName.emplace(SDLK_F1 + i, StrCat("F", i + 1));
}
for (int i = 0; i < 12; ++i) {
keyIDToKeyName.emplace(SDLK_F13 + i, StrCat("F", i + 13));
}

keyIDToKeyName.emplace(SDLK_KP_0, "KEYPADNUM 0");
for (int i = 0; i < 9; i++) {
Expand All @@ -1311,16 +1314,42 @@ KeymapperOptions::KeymapperOptions()

keyIDToKeyName.emplace(SDLK_LALT, "LALT");
keyIDToKeyName.emplace(SDLK_RALT, "RALT");

keyIDToKeyName.emplace(SDLK_SPACE, "SPACE");

keyIDToKeyName.emplace(SDLK_RCTRL, "RCONTROL");
keyIDToKeyName.emplace(SDLK_LCTRL, "LCONTROL");

keyIDToKeyName.emplace(SDLK_PRINTSCREEN, "PRINT");
keyIDToKeyName.emplace(SDLK_PAUSE, "PAUSE");
keyIDToKeyName.emplace(SDLK_TAB, "TAB");
keyIDToKeyName.emplace(SDL_BUTTON_MIDDLE | KeymapperMouseButtonMask, "MMOUSE");
keyIDToKeyName.emplace(SDL_BUTTON_X1 | KeymapperMouseButtonMask, "X1MOUSE");
keyIDToKeyName.emplace(SDL_BUTTON_X2 | KeymapperMouseButtonMask, "X2MOUSE");

keyIDToKeyName.emplace(SDLK_BACKQUOTE, "`");
keyIDToKeyName.emplace(SDLK_LEFTBRACKET, "[");
keyIDToKeyName.emplace(SDLK_RIGHTBRACKET, "]");
keyIDToKeyName.emplace(SDLK_BACKSLASH, "\\");
keyIDToKeyName.emplace(SDLK_SEMICOLON, ";");
keyIDToKeyName.emplace(SDLK_QUOTE, "'");
keyIDToKeyName.emplace(SDLK_COMMA, ",");
keyIDToKeyName.emplace(SDLK_PERIOD, ".");
keyIDToKeyName.emplace(SDLK_SLASH, "/");

keyIDToKeyName.emplace(SDLK_BACKSPACE, "BACKSPACE");
keyIDToKeyName.emplace(SDLK_CAPSLOCK, "CAPSLOCK");
keyIDToKeyName.emplace(SDLK_SCROLLLOCK, "SCROLLLOCK");
keyIDToKeyName.emplace(SDLK_INSERT, "INSERT");
keyIDToKeyName.emplace(SDLK_DELETE, "DELETE");
keyIDToKeyName.emplace(SDLK_HOME, "HOME");
keyIDToKeyName.emplace(SDLK_END, "END");

keyIDToKeyName.emplace(SDLK_KP_DIVIDE, "KEYPAD /");
keyIDToKeyName.emplace(SDLK_KP_MULTIPLY, "KEYPAD *");
keyIDToKeyName.emplace(SDLK_KP_ENTER, "KEYPAD ENTER");
keyIDToKeyName.emplace(SDLK_KP_PERIOD, "KEYPAD DECIMAL");

keyNameToKeyID.reserve(keyIDToKeyName.size());
for (const auto &[key, value] : keyIDToKeyName) {
keyNameToKeyID.emplace(value, key);
Expand Down

0 comments on commit 9123f01

Please sign in to comment.