Browse Source

Fix print screen for different print screen key bindings (#6060)

pull/6151/head
DakkJaniels 3 years ago committed by GitHub
parent
commit
e485493a3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      Source/DiabloUI/diabloui.cpp
  2. 4
      Source/diablo.cpp
  3. 21
      Source/options.cpp
  4. 4
      Source/options.h

5
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) {

4
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<SDL_Keycode>(button | KeymapperMouseButtonMask));
}
}

21
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<SDL_Keycode>(static_cast<Sint32>(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) {

4
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;

Loading…
Cancel
Save