diff --git a/irr/include/IrrlichtDevice.h b/irr/include/IrrlichtDevice.h index cf688b7e59102..74a40c6052b82 100644 --- a/irr/include/IrrlichtDevice.h +++ b/irr/include/IrrlichtDevice.h @@ -339,7 +339,13 @@ class IrrlichtDevice : public virtual IReferenceCounted //! Get the scancode of the corresponding keycode. virtual u32 getScancodeFromKey(const KeyCode &key) const { - return key.index() == 0 ? std::get(key) : KEY_KEY_CODES_COUNT + std::get(key); + if (key.index() == 0) { + const auto keycode = std::get(key); + // treat KEY_UNKNOWN and KEY_KEY_CODES_COUNT as the same and return 0. + return KeyCode::isValid(keycode) ? keycode : 0; + } + const auto keychar = std::get(key); + return keychar == 0 ? 0 : KEY_KEY_CODES_COUNT + keychar; } //! Get the keycode of the corresponding scancode. @@ -352,6 +358,15 @@ class IrrlichtDevice : public virtual IReferenceCounted key.emplace(scancode - KEY_KEY_CODES_COUNT); return key; } + +protected: + + // TODO: This is just some boilerplate for non-SDL devices. Remove this once we fully switch to SDL. + void fillScancode(SEvent &irrevent) + { + auto &keyinput = irrevent.KeyInput; + keyinput.SystemKeyCode = getScancodeFromKey(KeyCode(keyinput.Key, keyinput.Char)); + } }; } // end namespace irr diff --git a/irr/src/CIrrDeviceLinux.cpp b/irr/src/CIrrDeviceLinux.cpp index 5491d20375020..3bb3a2dfe14e7 100644 --- a/irr/src/CIrrDeviceLinux.cpp +++ b/irr/src/CIrrDeviceLinux.cpp @@ -881,10 +881,19 @@ bool CIrrDeviceLinux::run() irrevent.EventType = irr::EET_KEY_INPUT_EVENT; irrevent.KeyInput.PressedDown = false; - irrevent.KeyInput.Char = 0; // on release that's undefined irrevent.KeyInput.Control = (event.xkey.state & ControlMask) != 0; irrevent.KeyInput.Shift = (event.xkey.state & ShiftMask) != 0; irrevent.KeyInput.Key = getKeyCode(event); + { // Pass a char on release as well since this is needed for the scancode stub. + union + { + char buf[8]; + wchar_t wbuf[2]; + } tmp = {{0}}; + XLookupString(&event.xkey, tmp.buf, sizeof(tmp.buf), NULL, NULL); + irrevent.KeyInput.Char = tmp.wbuf[0]; + } + fillScancode(irrevent); postEventFromUser(irrevent); break; @@ -941,6 +950,7 @@ bool CIrrDeviceLinux::run() irrevent.KeyInput.Control = (event.xkey.state & ControlMask) != 0; irrevent.KeyInput.Shift = (event.xkey.state & ShiftMask) != 0; irrevent.KeyInput.Key = getKeyCode(event); + fillScancode(irrevent); postEventFromUser(irrevent); } break; diff --git a/irr/src/CIrrDeviceOSX.mm b/irr/src/CIrrDeviceOSX.mm index 67c0ce05ce0a4..bd3bd884bfe28 100644 --- a/irr/src/CIrrDeviceOSX.mm +++ b/irr/src/CIrrDeviceOSX.mm @@ -770,6 +770,7 @@ - (BOOL)isQuit IsShiftDown = ievent.KeyInput.Shift; + fillScancode(ievent); postEventFromUser(ievent); } @@ -780,6 +781,7 @@ - (BOOL)isQuit IsControlDown = ievent.KeyInput.Control; + fillScancode(ievent); postEventFromUser(ievent); } @@ -981,6 +983,7 @@ - (BOOL)isQuit ievent.KeyInput.Shift = ([(NSEvent *)event modifierFlags] & NSShiftKeyMask) != 0; ievent.KeyInput.Control = ([(NSEvent *)event modifierFlags] & NSControlKeyMask) != 0; ievent.KeyInput.Char = mchar; + fillScancode(ievent); if (skipCommand) ievent.KeyInput.Control = true; diff --git a/irr/src/CIrrDeviceWin32.cpp b/irr/src/CIrrDeviceWin32.cpp index c2876fccefc34..6434a7b415dbe 100644 --- a/irr/src/CIrrDeviceWin32.cpp +++ b/irr/src/CIrrDeviceWin32.cpp @@ -662,6 +662,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if ((allKeys[VK_MENU] & 0x80) != 0) event.KeyInput.Control = 0; + fillScancode(event); + dev = getDeviceFromHWnd(hWnd); if (dev) dev->postEventFromUser(event);