Platform/Win32/Win32Keyboard: skip Win32MsgBuffer and handle event directly in handleMessage()
This commit is contained in:
parent
e75d373933
commit
390be8f740
3 changed files with 16 additions and 47 deletions
|
|
@ -31,7 +31,7 @@ LRESULT Win32EventQueue::processMessage(MSG msg, Event& event)
|
||||||
OutputDebugString("WM_KEYDOWN\n");
|
OutputDebugString("WM_KEYDOWN\n");
|
||||||
//SetCapture(msg.hwnd);
|
//SetCapture(msg.hwnd);
|
||||||
|
|
||||||
if (Win32Keyboard::handleMessage(msg)) {
|
if (Win32Keyboard::handleMessage(msg, event)) {
|
||||||
// Keyboard did handle the message.
|
// Keyboard did handle the message.
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,13 @@
|
||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
#include <Spectre/Input/InputEvent.h>
|
#include <Spectre/System/Event.h>
|
||||||
#include <Spectre/Input/InputModule.h>
|
#include <Spectre/Input/InputModule.h>
|
||||||
#include "Win32Input.h"
|
#include "Win32Input.h"
|
||||||
#include "Win32Keyboard.h"
|
#include "Win32Keyboard.h"
|
||||||
#include "Win32MsgBuffer.h"
|
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
static Win32MsgBuffer msg_buf;
|
|
||||||
|
|
||||||
static const Keyboard::Key deviceToKey[256] = {
|
static const Keyboard::Key deviceToKey[256] = {
|
||||||
/* 0 1 2 3 4 5 6 7 */
|
/* 0 1 2 3 4 5 6 7 */
|
||||||
|
|
@ -63,8 +61,6 @@ static const Keyboard::Key deviceToKey[256] = {
|
||||||
|
|
||||||
void Win32Keyboard::init()
|
void Win32Keyboard::init()
|
||||||
{
|
{
|
||||||
Win32Input::inputMsgBuffer.enabled = true;
|
|
||||||
|
|
||||||
memset(m_btnState, 0, sizeof(m_btnState) / sizeof(m_btnState[0]));
|
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)
|
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
|
} // namespace sp
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#define PLATFORM_WIN32_KEYBOARD_H
|
#define PLATFORM_WIN32_KEYBOARD_H
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <Spectre/System/Event.h>
|
||||||
#include <Spectre/Input/Keyboard.h>
|
#include <Spectre/Input/Keyboard.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
@ -14,7 +15,8 @@ public :
|
||||||
|
|
||||||
bool isKeyDown(Keyboard::Key key);
|
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 :
|
protected :
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue