diff --git a/src/app/app.cpp b/src/app/app.cpp index 2d253aa3..83948c66 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -1425,7 +1425,7 @@ Event CApplication::CreateVirtualEvent(const Event& sourceEvent) if ((sourceEvent.type == EVENT_KEY_DOWN) || (sourceEvent.type == EVENT_KEY_UP)) { auto sourceData = sourceEvent.GetData(); - auto virtualKey = GetVirtualKey(sourceData->key); + auto virtualKey = GetVirtualKey(sourceData->key, sourceEvent.kmodState); if (virtualKey == sourceData->key) { diff --git a/src/common/key.cpp b/src/common/key.cpp index 81fd4610..e037766c 100644 --- a/src/common/key.cpp +++ b/src/common/key.cpp @@ -19,7 +19,7 @@ #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)) return VIRTUAL_KMOD(CTRL); @@ -33,5 +33,26 @@ unsigned int GetVirtualKey(unsigned int key) if(key == KEY(KP_ENTER)) 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; } diff --git a/src/common/key.h b/src/common/key.h index 57bbd457..2b972321 100644 --- a/src/common/key.h +++ b/src/common/key.h @@ -62,7 +62,7 @@ enum VirtualKmod #define VIRTUAL_KMOD(x) VIRTUAL_KMOD_ ## x //! 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 // num is number of joystick button diff --git a/src/ui/controls/key.cpp b/src/ui/controls/key.cpp index 89dffbff..e5751d2f 100644 --- a/src/ui/controls/key.cpp +++ b/src/ui/controls/key.cpp @@ -75,7 +75,7 @@ bool CKey::EventProcess(const Event &event) if (event.type == EVENT_KEY_DOWN && m_catch) { m_catch = false; - unsigned int key = GetVirtualKey(event.GetData()->key); + unsigned int key = GetVirtualKey(event.GetData()->key, event.kmodState); if (TestKey(key)) // impossible ? {