fix issues in ctrl/shift/alt states on win32

This commit is contained in:
Eduardo Bart 2012-04-04 19:35:56 -03:00
parent c4693fb7b9
commit 1410031e02
2 changed files with 47 additions and 18 deletions

View File

@ -45,19 +45,26 @@ void PlatformWindow::updateUnmaximizedCoords()
void PlatformWindow::processKeyDown(Fw::Key keyCode)
{
if(keyCode == Fw::KeyUnknown || m_keysState[keyCode])
if(keyCode == Fw::KeyUnknown)
return;
if(keyCode == Fw::KeyCtrl) {
m_inputEvent.keyboardModifiers |= Fw::KeyboardCtrlModifier;
return;
} else if(keyCode == Fw::KeyAlt) {
m_inputEvent.keyboardModifiers |= Fw::KeyboardAltModifier;
return;
} else if(keyCode == Fw::KeyShift) {
m_inputEvent.keyboardModifiers |= Fw::KeyboardShiftModifier;
return;
}
if(m_keysState[keyCode])
return;
m_keysState[keyCode] = true;
m_lastKeysPress[keyCode] = -1;
if(keyCode == Fw::KeyCtrl)
m_inputEvent.keyboardModifiers |= Fw::KeyboardCtrlModifier;
else if(keyCode == Fw::KeyAlt)
m_inputEvent.keyboardModifiers |= Fw::KeyboardAltModifier;
else if(keyCode == Fw::KeyShift)
m_inputEvent.keyboardModifiers |= Fw::KeyboardShiftModifier;
m_inputEvent.reset(Fw::KeyDownInputEvent);
m_inputEvent.type = Fw::KeyDownInputEvent;
m_inputEvent.keyCode = keyCode;
@ -75,18 +82,25 @@ void PlatformWindow::processKeyDown(Fw::Key keyCode)
void PlatformWindow::processKeyUp(Fw::Key keyCode)
{
if(keyCode == Fw::KeyUnknown || !m_keysState[keyCode])
if(keyCode == Fw::KeyUnknown)
return;
if(keyCode == Fw::KeyCtrl) {
m_inputEvent.keyboardModifiers &= ~Fw::KeyboardCtrlModifier;
return;
} else if(keyCode == Fw::KeyAlt) {
m_inputEvent.keyboardModifiers &= ~Fw::KeyboardAltModifier;
return;
} else if(keyCode == Fw::KeyShift) {
m_inputEvent.keyboardModifiers &= ~Fw::KeyboardShiftModifier;
return;
}
if(!m_keysState[keyCode])
return;
m_keysState[keyCode] = false;
if(keyCode == Fw::KeyCtrl)
m_inputEvent.keyboardModifiers &= ~Fw::KeyboardCtrlModifier;
else if(keyCode == Fw::KeyAlt)
m_inputEvent.keyboardModifiers &= ~Fw::KeyboardAltModifier;
else if(keyCode == Fw::KeyShift)
m_inputEvent.keyboardModifiers &= ~Fw::KeyboardShiftModifier;
if(m_onInputEvent) {
m_inputEvent.reset(Fw::KeyUpInputEvent);
m_onInputEvent(m_inputEvent);

View File

@ -446,14 +446,29 @@ Fw::Key WIN32Window::retranslateVirtualKey(WPARAM wParam, LPARAM lParam)
}
}
Fw::Key key = Fw::KeyUnknown;
if(m_keyMap.find(wParam) != m_keyMap.end())
return m_keyMap[wParam];
key = m_keyMap[wParam];
return Fw::KeyUnknown;
// actually ignore alt/ctrl/shift keys, they is states are already stored in m_inputEvent.keyboardModifiers
if(key == Fw::KeyAlt || key == Fw::KeyCtrl || key == Fw::KeyShift)
key = Fw::KeyUnknown;
return key;
}
#define IsKeyDown(a) (GetKeyState(a) & 0x80)
LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
m_inputEvent.keyboardModifiers = 0;
if(IsKeyDown(VK_CONTROL))
m_inputEvent.keyboardModifiers |= Fw::KeyboardCtrlModifier;
if(IsKeyDown(VK_SHIFT))
m_inputEvent.keyboardModifiers |= Fw::KeyboardShiftModifier;
if(IsKeyDown(VK_MENU))
m_inputEvent.keyboardModifiers |= Fw::KeyboardAltModifier;
switch(uMsg)
{
case WM_SETCURSOR: {