Add workaround for numpad home/end keys etc

fix-squashed-planets
Rasmus Brönnegård 2022-01-23 13:16:13 +01:00
parent 53053b901f
commit be8d37241a
4 changed files with 25 additions and 4 deletions

View File

@ -1425,7 +1425,7 @@ Event CApplication::CreateVirtualEvent(const Event& sourceEvent)
if ((sourceEvent.type == EVENT_KEY_DOWN) || (sourceEvent.type == EVENT_KEY_UP)) if ((sourceEvent.type == EVENT_KEY_DOWN) || (sourceEvent.type == EVENT_KEY_UP))
{ {
auto sourceData = sourceEvent.GetData<KeyEventData>(); auto sourceData = sourceEvent.GetData<KeyEventData>();
auto virtualKey = GetVirtualKey(sourceData->key); auto virtualKey = GetVirtualKey(sourceData->key, sourceEvent.kmodState);
if (virtualKey == sourceData->key) if (virtualKey == sourceData->key)
{ {

View File

@ -19,7 +19,7 @@
#include "common/key.h" #include "common/key.h"
unsigned int GetVirtualKey(unsigned int key) unsigned int GetVirtualKey(unsigned int key, unsigned int kmodState)
{ {
if(key == KEY(LCTRL) || key == KEY(RCTRL)) if(key == KEY(LCTRL) || key == KEY(RCTRL))
return VIRTUAL_KMOD(CTRL); return VIRTUAL_KMOD(CTRL);
@ -33,5 +33,26 @@ unsigned int GetVirtualKey(unsigned int key)
if(key == KEY(KP_ENTER)) if(key == KEY(KP_ENTER))
return KEY(RETURN); return KEY(RETURN);
// Remap keypad navigation keys as a workaround for the SDL issue: https://github.com/libsdl-org/SDL/issues/1766
if ((kmodState & KEY_MOD(NUM)) == 0)
{
if(key == KEY(KP_7))
return KEY(HOME);
if(key == KEY(KP_1))
return KEY(END);
if(key == KEY(KP_9))
return KEY(PAGEUP);
if(key == KEY(KP_3))
return KEY(PAGEDOWN);
if(key == KEY(KP_4))
return KEY(LEFT);
if(key == KEY(KP_6))
return KEY(RIGHT);
if(key == KEY(KP_8))
return KEY(UP);
if(key == KEY(KP_2))
return KEY(DOWN);
}
return key; return key;
} }

View File

@ -62,7 +62,7 @@ enum VirtualKmod
#define VIRTUAL_KMOD(x) VIRTUAL_KMOD_ ## x #define VIRTUAL_KMOD(x) VIRTUAL_KMOD_ ## x
//! Converts individual codes to virtual keys if needed //! Converts individual codes to virtual keys if needed
unsigned int GetVirtualKey(unsigned int key); unsigned int GetVirtualKey(unsigned int key, unsigned int kmodState);
// Virtual key code generated on joystick button presses // Virtual key code generated on joystick button presses
// num is number of joystick button // num is number of joystick button

View File

@ -75,7 +75,7 @@ bool CKey::EventProcess(const Event &event)
if (event.type == EVENT_KEY_DOWN && m_catch) if (event.type == EVENT_KEY_DOWN && m_catch)
{ {
m_catch = false; m_catch = false;
unsigned int key = GetVirtualKey(event.GetData<KeyEventData>()->key); unsigned int key = GetVirtualKey(event.GetData<KeyEventData>()->key, event.kmodState);
if (TestKey(key)) // impossible ? if (TestKey(key)) // impossible ?
{ {