fix key events for win32

master
Eduardo Bart 13 years ago
parent 7bcf7f536e
commit 452d1a76b0

@ -231,7 +231,7 @@ namespace Fw
KeyTextInputEvent, KeyTextInputEvent,
KeyDownInputEvent, KeyDownInputEvent,
KeyPressInputEvent, KeyPressInputEvent,
KeyReleaseInputEvent, KeyUpInputEvent,
MousePressInputEvent, MousePressInputEvent,
MouseReleaseInputEvent, MouseReleaseInputEvent,
MouseMoveInputEvent, MouseMoveInputEvent,

@ -31,6 +31,8 @@ WIN32Window window;
X11Window window; X11Window window;
#endif #endif
#include <framework/core/clock.h>
PlatformWindow& g_window = window; PlatformWindow& g_window = window;
void PlatformWindow::updateUnmaximizedCoords() void PlatformWindow::updateUnmaximizedCoords()
@ -71,7 +73,7 @@ void PlatformWindow::processKeyDown(Fw::Key keyCode)
} }
} }
void PlatformWindow::processKeyRelease(Fw::Key keyCode) void PlatformWindow::processKeyUp(Fw::Key keyCode)
{ {
if(keyCode == Fw::KeyUnknown || !m_keysState[keyCode]) if(keyCode == Fw::KeyUnknown || !m_keysState[keyCode])
return; return;
@ -86,7 +88,7 @@ void PlatformWindow::processKeyRelease(Fw::Key keyCode)
m_inputEvent.keyboardModifiers &= ~Fw::KeyboardShiftModifier; m_inputEvent.keyboardModifiers &= ~Fw::KeyboardShiftModifier;
if(m_onInputEvent) { if(m_onInputEvent) {
m_inputEvent.reset(Fw::KeyReleaseInputEvent); m_inputEvent.reset(Fw::KeyUpInputEvent);
m_onInputEvent(m_inputEvent); m_onInputEvent(m_inputEvent);
} }
} }
@ -100,7 +102,7 @@ void PlatformWindow::releaseAllKeys()
if(!pressed) if(!pressed)
continue; continue;
processKeyRelease(keyCode); processKeyUp(keyCode);
} }
} }

@ -93,7 +93,7 @@ protected:
void updateUnmaximizedCoords(); void updateUnmaximizedCoords();
void processKeyDown(Fw::Key keyCode); void processKeyDown(Fw::Key keyCode);
void processKeyRelease(Fw::Key keyCode); void processKeyUp(Fw::Key keyCode);
void releaseAllKeys(); void releaseAllKeys();
void fireKeysPress(); void fireKeysPress();

@ -60,10 +60,13 @@ WIN32Window::WIN32Window()
m_keyMap[VK_SNAPSHOT] = Fw::KeyPrintScreen; m_keyMap[VK_SNAPSHOT] = Fw::KeyPrintScreen;
m_keyMap[VK_PAUSE] = Fw::KeyPause; m_keyMap[VK_PAUSE] = Fw::KeyPause;
m_keyMap[VK_CONTROL] = Fw::KeyCtrl;
m_keyMap[VK_LCONTROL] = Fw::KeyCtrl; m_keyMap[VK_LCONTROL] = Fw::KeyCtrl;
m_keyMap[VK_RCONTROL] = Fw::KeyCtrl; m_keyMap[VK_RCONTROL] = Fw::KeyCtrl;
m_keyMap[VK_SHIFT] = Fw::KeyShift;
m_keyMap[VK_LSHIFT] = Fw::KeyShift; m_keyMap[VK_LSHIFT] = Fw::KeyShift;
m_keyMap[VK_RSHIFT] = Fw::KeyShift; m_keyMap[VK_RSHIFT] = Fw::KeyShift;
m_keyMap[VK_MENU] = Fw::KeyAlt;
m_keyMap[VK_LMENU] = Fw::KeyAlt; m_keyMap[VK_LMENU] = Fw::KeyAlt;
m_keyMap[VK_RMENU] = Fw::KeyAltGr; m_keyMap[VK_RMENU] = Fw::KeyAltGr;
m_keyMap[VK_LWIN] = Fw::KeyMeta; m_keyMap[VK_LWIN] = Fw::KeyMeta;
@ -376,6 +379,8 @@ void WIN32Window::maximize()
void WIN32Window::poll() void WIN32Window::poll()
{ {
fireKeysPress();
for(int i=0;i<2;++i) { for(int i=0;i<2;++i) {
MSG msg; MSG msg;
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
@ -394,13 +399,16 @@ void WIN32Window::poll()
LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
m_inputEvent.type = Fw::NoInputEvent;
m_inputEvent.mouseButton = Fw::MouseNoButton;
m_inputEvent.keyCode = Fw::KeyUnknown;
m_inputEvent.keyText = "";
m_inputEvent.mouseMoved = Point();
m_inputEvent.wheelDirection = Fw::MouseNoWheel;
/*
m_inputEvent.keyboardModifiers = 0;
if(HIWORD(GetKeyState(VK_CONTROL)))
m_inputEvent.keyboardModifiers |= Fw::KeyboardCtrlModifier;
if(HIWORD(GetKeyState(VK_MENU)))
m_inputEvent.keyboardModifiers |= Fw::KeyboardAltModifier;
if(HIWORD(GetKeyState(VK_SHIFT)))
m_inputEvent.keyboardModifiers |= Fw::KeyboardShiftModifier;
*/
switch(uMsg) switch(uMsg)
{ {
case WM_ACTIVATE: { case WM_ACTIVATE: {
@ -409,9 +417,9 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
} }
case WM_CHAR: { case WM_CHAR: {
if(wParam >= 32 && wParam <= 255) { if(wParam >= 32 && wParam <= 255) {
m_inputEvent.type = Fw::KeyPressInputEvent; m_inputEvent.reset(Fw::KeyTextInputEvent);
m_inputEvent.keyCode = Fw::KeyUnknown;
m_inputEvent.keyText = wParam; m_inputEvent.keyText = wParam;
m_onInputEvent(m_inputEvent);
} }
break; break;
} }
@ -419,55 +427,63 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
m_onClose(); m_onClose();
break; break;
} }
case WM_KEYDOWN: case WM_KEYDOWN: {
processKeyDown(m_keyMap[wParam]);
break;
}
case WM_KEYUP: { case WM_KEYUP: {
if(m_keyMap.find(wParam) != m_keyMap.end()) { processKeyUp(m_keyMap[wParam]);
m_inputEvent.type = (uMsg == WM_KEYDOWN) ? Fw::KeyPressInputEvent : Fw::KeyReleaseInputEvent;
m_inputEvent.keyCode = m_keyMap[wParam];
}
break; break;
} }
case WM_LBUTTONDOWN: { case WM_LBUTTONDOWN: {
m_inputEvent.type = Fw::MousePressInputEvent; m_inputEvent.reset(Fw::MousePressInputEvent);
m_inputEvent.mouseButton = Fw::MouseLeftButton; m_inputEvent.mouseButton = Fw::MouseLeftButton;
m_onInputEvent(m_inputEvent);
break; break;
} }
case WM_LBUTTONUP: { case WM_LBUTTONUP: {
m_inputEvent.type = Fw::MouseReleaseInputEvent; m_inputEvent.reset(Fw::MouseReleaseInputEvent);
m_inputEvent.mouseButton = Fw::MouseLeftButton; m_inputEvent.mouseButton = Fw::MouseLeftButton;
m_onInputEvent(m_inputEvent);
break; break;
} }
case WM_MBUTTONDOWN: { case WM_MBUTTONDOWN: {
m_inputEvent.type = Fw::MousePressInputEvent; m_inputEvent.reset(Fw::MousePressInputEvent);
m_inputEvent.mouseButton = Fw::MouseMidButton; m_inputEvent.mouseButton = Fw::MouseMidButton;
m_onInputEvent(m_inputEvent);
break; break;
} }
case WM_MBUTTONUP: { case WM_MBUTTONUP: {
m_inputEvent.type = Fw::MouseReleaseInputEvent; m_inputEvent.reset(Fw::MouseReleaseInputEvent);
m_inputEvent.mouseButton = Fw::MouseMidButton; m_inputEvent.mouseButton = Fw::MouseMidButton;
m_onInputEvent(m_inputEvent);
break; break;
} }
case WM_RBUTTONDOWN: { case WM_RBUTTONDOWN: {
m_inputEvent.type = Fw::MousePressInputEvent; m_inputEvent.reset(Fw::MousePressInputEvent);
m_inputEvent.mouseButton = Fw::MouseRightButton; m_inputEvent.mouseButton = Fw::MouseRightButton;
m_onInputEvent(m_inputEvent);
break; break;
} }
case WM_RBUTTONUP: { case WM_RBUTTONUP: {
m_inputEvent.type = Fw::MouseReleaseInputEvent; m_inputEvent.reset(Fw::MouseReleaseInputEvent);
m_inputEvent.mouseButton = Fw::MouseRightButton; m_inputEvent.mouseButton = Fw::MouseRightButton;
m_onInputEvent(m_inputEvent);
break; break;
} }
case WM_MOUSEMOVE: { case WM_MOUSEMOVE: {
m_inputEvent.type = Fw::MouseMoveInputEvent; m_inputEvent.reset(Fw::MouseMoveInputEvent);
Point newMousePos(LOWORD(lParam), HIWORD(lParam)); Point newMousePos(LOWORD(lParam), HIWORD(lParam));
m_inputEvent.mouseMoved = newMousePos - m_inputEvent.mousePos; m_inputEvent.mouseMoved = newMousePos - m_inputEvent.mousePos;
m_inputEvent.mousePos = newMousePos; m_inputEvent.mousePos = newMousePos;
m_onInputEvent(m_inputEvent);
break; break;
} }
case WM_MOUSEWHEEL: { case WM_MOUSEWHEEL: {
m_inputEvent.type = Fw::MouseWheelInputEvent; m_inputEvent.reset(Fw::MouseWheelInputEvent);
m_inputEvent.mouseButton = Fw::MouseMidButton; m_inputEvent.mouseButton = Fw::MouseMidButton;
m_inputEvent.wheelDirection = HIWORD(wParam) > 0 ? Fw::MouseWheelUp : Fw::MouseWheelDown; m_inputEvent.wheelDirection = HIWORD(wParam) > 0 ? Fw::MouseWheelUp : Fw::MouseWheelDown;
m_onInputEvent(m_inputEvent);
break; break;
} }
case WM_MOVE: { case WM_MOVE: {
@ -496,17 +512,6 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
return DefWindowProc(hWnd, uMsg, wParam, lParam); return DefWindowProc(hWnd, uMsg, wParam, lParam);
} }
if(m_inputEvent.type != Fw::NoInputEvent) {
m_inputEvent.keyboardModifiers = 0;
if(HIWORD(GetKeyState(VK_CONTROL)))
m_inputEvent.keyboardModifiers |= Fw::KeyboardCtrlModifier;
if(HIWORD(GetKeyState(VK_MENU)))
m_inputEvent.keyboardModifiers |= Fw::KeyboardAltModifier;
if(HIWORD(GetKeyState(VK_SHIFT)))
m_inputEvent.keyboardModifiers |= Fw::KeyboardShiftModifier;
m_onInputEvent(m_inputEvent);
}
return 0; return 0;
} }

@ -550,7 +550,7 @@ void X11Window::poll()
if(event.type == KeyPress) if(event.type == KeyPress)
processKeyDown(keyCode); processKeyDown(keyCode);
else if(event.type == KeyRelease) else if(event.type == KeyRelease)
processKeyRelease(keyCode); processKeyUp(keyCode);
} }
// call filter because xim will discard KeyPress events when keys still composing // call filter because xim will discard KeyPress events when keys still composing

@ -442,7 +442,8 @@ bool UILineEdit::onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilt
} else } else
return false; return false;
return true; return true;
} } else
dump << "what?";
return false; return false;
} }

@ -68,8 +68,8 @@ void UIManager::inputEvent(const InputEvent& event)
case Fw::KeyPressInputEvent: case Fw::KeyPressInputEvent:
m_keyboardReceiver->propagateOnKeyPress(event.keyCode, event.keyboardModifiers, event.wouldFilter); m_keyboardReceiver->propagateOnKeyPress(event.keyCode, event.keyboardModifiers, event.wouldFilter);
break; break;
case Fw::KeyReleaseInputEvent: case Fw::KeyUpInputEvent:
m_keyboardReceiver->propagateOnKeyRelease(event.keyCode, event.keyboardModifiers); m_keyboardReceiver->propagateOnKeyUp(event.keyCode, event.keyboardModifiers);
break; break;
case Fw::MousePressInputEvent: case Fw::MousePressInputEvent:
m_keyboardReceiver->propagateOnMousePress(event.mousePos, event.mouseButton); m_keyboardReceiver->propagateOnMousePress(event.mousePos, event.mouseButton);

@ -1071,9 +1071,9 @@ bool UIWidget::onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter
return callLuaField<bool>("onKeyPress", keyCode, keyboardModifiers, wouldFilter); return callLuaField<bool>("onKeyPress", keyCode, keyboardModifiers, wouldFilter);
} }
bool UIWidget::onKeyRelease(uchar keyCode, int keyboardModifiers) bool UIWidget::onKeyUp(uchar keyCode, int keyboardModifiers)
{ {
return callLuaField<bool>("onKeyRelease", keyCode, keyboardModifiers); return callLuaField<bool>("onKeyUp", keyCode, keyboardModifiers);
} }
bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button) bool UIWidget::onMousePress(const Point& mousePos, Fw::MouseButton button)
@ -1165,7 +1165,7 @@ bool UIWidget::propagateOnKeyPress(uchar keyCode, int keyboardModifiers, bool wo
return onKeyPress(keyCode, keyboardModifiers, wouldFilter); return onKeyPress(keyCode, keyboardModifiers, wouldFilter);
} }
bool UIWidget::propagateOnKeyRelease(uchar keyCode, int keyboardModifiers) bool UIWidget::propagateOnKeyUp(uchar keyCode, int keyboardModifiers)
{ {
// do a backup of children list, because it may change while looping it // do a backup of children list, because it may change while looping it
UIWidgetList children; UIWidgetList children;
@ -1180,11 +1180,11 @@ bool UIWidget::propagateOnKeyRelease(uchar keyCode, int keyboardModifiers)
} }
for(const UIWidgetPtr& child : children) { for(const UIWidgetPtr& child : children) {
if(child->propagateOnKeyRelease(keyCode, keyboardModifiers)) if(child->propagateOnKeyUp(keyCode, keyboardModifiers))
return true; return true;
} }
return onKeyRelease(keyCode, keyboardModifiers); return onKeyUp(keyCode, keyboardModifiers);
} }
bool UIWidget::propagateOnMousePress(const Point& mousePos, Fw::MouseButton button) bool UIWidget::propagateOnMousePress(const Point& mousePos, Fw::MouseButton button)

@ -164,7 +164,7 @@ protected:
virtual bool onKeyText(const std::string& keyText); virtual bool onKeyText(const std::string& keyText);
virtual bool onKeyDown(uchar keyCode, int keyboardModifiers); virtual bool onKeyDown(uchar keyCode, int keyboardModifiers);
virtual bool onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter); virtual bool onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter);
virtual bool onKeyRelease(uchar keyCode, int keyboardModifiers); virtual bool onKeyUp(uchar keyCode, int keyboardModifiers);
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button); virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button); virtual void onMouseRelease(const Point& mousePos, Fw::MouseButton button);
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved); virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
@ -173,7 +173,7 @@ protected:
bool propagateOnKeyText(const std::string& keyText); bool propagateOnKeyText(const std::string& keyText);
bool propagateOnKeyDown(uchar keyCode, int keyboardModifiers); bool propagateOnKeyDown(uchar keyCode, int keyboardModifiers);
bool propagateOnKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter); bool propagateOnKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter);
bool propagateOnKeyRelease(uchar keyCode, int keyboardModifiers); bool propagateOnKeyUp(uchar keyCode, int keyboardModifiers);
bool propagateOnMousePress(const Point& mousePos, Fw::MouseButton button); bool propagateOnMousePress(const Point& mousePos, Fw::MouseButton button);
void propagateOnMouseRelease(const Point& mousePos, Fw::MouseButton button); void propagateOnMouseRelease(const Point& mousePos, Fw::MouseButton button);
bool propagateOnMouseMove(const Point& mousePos, const Point& mouseMoved); bool propagateOnMouseMove(const Point& mousePos, const Point& mouseMoved);

@ -57,6 +57,8 @@ bool UIGame::onKeyPress(uchar keyCode, int keyboardModifiers, bool wouldFilter)
} else if(keyCode == Fw::KeyNumpad7) { } else if(keyCode == Fw::KeyNumpad7) {
g_game.walk(Otc::NorthWest); g_game.walk(Otc::NorthWest);
return true; return true;
} else if(wouldFilter) {
return false;
} else if(keyCode == Fw::KeyReturn || keyCode == Fw::KeyEnter) { } else if(keyCode == Fw::KeyReturn || keyCode == Fw::KeyEnter) {
g_game.talk(chatLineEdit->getText()); g_game.talk(chatLineEdit->getText());
chatLineEdit->clearText(); chatLineEdit->clearText();

Loading…
Cancel
Save