From 390be8f7403261705b85da0b65070e50e2c35c00 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sat, 1 Feb 2020 11:26:37 +0100 Subject: [PATCH] Platform/Win32/Win32Keyboard: skip Win32MsgBuffer and handle event directly in handleMessage() --- source/Platform/Win32/Win32EventQueue.cpp | 2 +- source/Platform/Win32/Win32Keyboard.cpp | 57 +++++------------------ source/Platform/Win32/Win32Keyboard.h | 4 +- 3 files changed, 16 insertions(+), 47 deletions(-) diff --git a/source/Platform/Win32/Win32EventQueue.cpp b/source/Platform/Win32/Win32EventQueue.cpp index c2b6b74..bf7a77e 100644 --- a/source/Platform/Win32/Win32EventQueue.cpp +++ b/source/Platform/Win32/Win32EventQueue.cpp @@ -31,7 +31,7 @@ LRESULT Win32EventQueue::processMessage(MSG msg, Event& event) OutputDebugString("WM_KEYDOWN\n"); //SetCapture(msg.hwnd); - if (Win32Keyboard::handleMessage(msg)) { + if (Win32Keyboard::handleMessage(msg, event)) { // Keyboard did handle the message. return 0; } diff --git a/source/Platform/Win32/Win32Keyboard.cpp b/source/Platform/Win32/Win32Keyboard.cpp index 8d37970..13fd328 100644 --- a/source/Platform/Win32/Win32Keyboard.cpp +++ b/source/Platform/Win32/Win32Keyboard.cpp @@ -1,15 +1,13 @@ #include -#include +#include #include #include "Win32Input.h" #include "Win32Keyboard.h" -#include "Win32MsgBuffer.h" namespace sp { -static Win32MsgBuffer msg_buf; static const Keyboard::Key deviceToKey[256] = { /* 0 1 2 3 4 5 6 7 */ @@ -63,8 +61,6 @@ static const Keyboard::Key deviceToKey[256] = { void Win32Keyboard::init() { - Win32Input::inputMsgBuffer.enabled = true; - memset(m_btnState, 0, sizeof(m_btnState) / sizeof(m_btnState[0])); } @@ -75,49 +71,20 @@ bool Win32Keyboard::isKeyDown(Keyboard::Key key) void Win32Keyboard::update(InputModule *input) { - for(int i = 0; i < msg_buf.index; i++) { - - MSG msg = msg_buf.messages[i]; - - if (msg.message == WM_KILLFOCUS) { - - for(int i = 0; i < Keyboard::Key::NUM_KEYS; i++) { - - if (m_btnState[i]) { - InputEvent event(InputEvent::Key); - event.key.code = (Keyboard::Key) i; - event.key.pressed = msg.message == WM_KEYDOWN; - - m_btnState[i] = false; - input->postInputEvent(event); - } - } - - continue; - } - - if (msg.message != WM_KEYDOWN && msg.message != WM_KEYUP) { - continue; - } - - Keyboard::Key key = deviceToKey[msg.wParam % 0xFF]; - - if (key != Keyboard::Key::Unknown) { - InputEvent event(InputEvent::Key); - event.key.code = key; - event.key.pressed = msg.message == WM_KEYDOWN; - - m_btnState[key] = event.key.pressed; - input->postInputEvent(event); - } - } - - msg_buf.index = 0; } -bool Win32Keyboard::handleMessage(MSG message) +bool Win32Keyboard::handleMessage(MSG msg, Event& event) { - return msg_buf.postMessage(message); + Keyboard::Key key = deviceToKey[msg.wParam % 0xFF]; + + if (key != Keyboard::Key::Unknown) { + event.type = Event::Key; + event.key.code = key; + event.key.pressed = msg.message == WM_KEYDOWN; + return true; + } + + return false; } } // namespace sp diff --git a/source/Platform/Win32/Win32Keyboard.h b/source/Platform/Win32/Win32Keyboard.h index 1280532..8da6718 100644 --- a/source/Platform/Win32/Win32Keyboard.h +++ b/source/Platform/Win32/Win32Keyboard.h @@ -3,6 +3,7 @@ #define PLATFORM_WIN32_KEYBOARD_H #include +#include #include namespace sp { @@ -14,7 +15,8 @@ public : bool isKeyDown(Keyboard::Key key); - static bool handleMessage(MSG message); + // Translate a Win32 Event to sp::Event, Called from Win32EventQueue + static bool handleMessage(MSG message, Event& event); protected :