1
0
Fork 0

Platform/Win32/Win32Keyboard: skip Win32MsgBuffer and handle event directly in handleMessage()

This commit is contained in:
Henrik Hautakoski 2020-02-01 11:26:37 +01:00
parent e75d373933
commit 390be8f740
No known key found for this signature in database
GPG key ID: 96765B12FEAC4745
3 changed files with 16 additions and 47 deletions

View file

@ -1,15 +1,13 @@
#include <Windows.h>
#include <Spectre/Input/InputEvent.h>
#include <Spectre/System/Event.h>
#include <Spectre/Input/InputModule.h>
#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