diff --git a/Source/DiabloUI/diabloui.cpp b/Source/DiabloUI/diabloui.cpp index 7809e274e..a688f6b71 100644 --- a/Source/DiabloUI/diabloui.cpp +++ b/Source/DiabloUI/diabloui.cpp @@ -463,11 +463,6 @@ void UiHandleEvents(SDL_Event *event) return; } - if (event->type == SDL_KEYUP && event->key.keysym.sym == SDLK_PRINTSCREEN) { - PrintScreen(SDLK_PRINTSCREEN); - return; - } - if (event->type == SDL_KEYDOWN && event->key.keysym.sym == SDLK_RETURN) { const Uint8 *state = SDLC_GetKeyState(); if (state[SDLC_KEYSTATE_LALT] != 0 || state[SDLC_KEYSTATE_RALT] != 0) { diff --git a/Source/diablo.cpp b/Source/diablo.cpp index c6fadf300..40ac6c149 100644 --- a/Source/diablo.cpp +++ b/Source/diablo.cpp @@ -440,7 +440,7 @@ void RightMouseDown(bool isShiftHeld) void ReleaseKey(SDL_Keycode vkey) { remap_keyboard_key(&vkey); - if ((sgnTimeoutCurs != CURSOR_NONE || dropGoldFlag) && vkey != SDLK_PRINTSCREEN) + if (sgnTimeoutCurs != CURSOR_NONE) return; sgOptions.Keymapper.KeyReleased(vkey); } @@ -660,7 +660,7 @@ void HandleMouseButtonUp(Uint8 button, uint16_t modState) LastMouseButtonAction = MouseActionType::None; sgbMouseDown = CLICK_NONE; } else { - sgOptions.Keymapper.KeyReleased(button | KeymapperMouseButtonMask); + sgOptions.Keymapper.KeyReleased(static_cast(button | KeymapperMouseButtonMask)); } } diff --git a/Source/options.cpp b/Source/options.cpp index 250857621..72116fbe4 100644 --- a/Source/options.cpp +++ b/Source/options.cpp @@ -1463,22 +1463,35 @@ void KeymapperOptions::KeyPressed(uint32_t key) const action.actionPressed(); } -void KeymapperOptions::KeyReleased(uint32_t key) const +void KeymapperOptions::KeyReleased(SDL_Keycode key) const { + if (key >= SDLK_a && key <= SDLK_z) { + key = static_cast(static_cast(key) - ('a' - 'A')); + } auto it = keyIDToAction.find(key); if (it == keyIDToAction.end()) return; // Ignore unmapped keys. const Action &action = it->second.get(); - // Check that the action can be triggered and that the chat textbox is not - // open. - if (!action.actionReleased || (action.enable && !action.enable()) || talkflag) + // Check that the action can be triggered and that the chat or gold textbox is not + // open. If either of those textboxes are open, only return if the key can be used for entry into the box + if (!action.actionReleased || (action.enable && !action.enable()) || ((talkflag && IsTextEntryKey(key)) || (dropGoldFlag && IsNumberEntryKey(key)))) return; action.actionReleased(); } +bool KeymapperOptions::IsTextEntryKey(SDL_Keycode vkey) const +{ + return IsAnyOf(vkey, SDLK_ESCAPE, SDLK_RETURN, SDLK_KP_ENTER, SDLK_BACKSPACE, SDLK_DOWN, SDLK_UP) || (vkey >= SDLK_SPACE && vkey <= SDLK_z); +} + +bool KeymapperOptions::IsNumberEntryKey(SDL_Keycode vkey) const +{ + return ((vkey >= SDLK_0 && vkey <= SDLK_9) || vkey == SDLK_BACKSPACE); +} + string_view KeymapperOptions::KeyNameForAction(string_view actionName) const { for (const Action &action : actions) { diff --git a/Source/options.h b/Source/options.h index 48303bef3..b01d2e79a 100644 --- a/Source/options.h +++ b/Source/options.h @@ -694,7 +694,9 @@ struct KeymapperOptions : OptionCategoryBase { unsigned index = 0); void CommitActions(); void KeyPressed(uint32_t key) const; - void KeyReleased(uint32_t key) const; + void KeyReleased(SDL_Keycode key) const; + bool IsTextEntryKey(SDL_Keycode vkey) const; + bool IsNumberEntryKey(SDL_Keycode vkey) const; string_view KeyNameForAction(string_view actionName) const; uint32_t KeyForAction(string_view actionName) const;