fix numpad keys on win32

This commit is contained in:
Eduardo Bart 2012-02-04 00:11:18 -02:00
parent d83804f2cb
commit aafe219532
8 changed files with 72 additions and 31 deletions

View File

@ -117,7 +117,6 @@ function Terminal.init()
Hotkeys.bindKeyDown('Down', function() navigateCommand(-1) end, commandLineEdit)
Hotkeys.bindKeyDown('Tab', completeCommand, commandLineEdit)
Hotkeys.bindKeyDown('Enter', doCommand, commandLineEdit)
Hotkeys.bindKeyDown('Return', doCommand, commandLineEdit)
terminalBuffer = terminalWidget:getChildById('terminalBuffer')
Logger.setOnLog(onLog)

View File

@ -63,7 +63,6 @@ KeyUnknown = 0
KeyEscape = 1
KeyTab = 2
KeyBackspace = 3
KeyReturn = 4
KeyEnter = 5
KeyInsert = 6
KeyDelete = 7
@ -183,7 +182,6 @@ KeyCodeDescs = {
[KeyEscape] = 'Escape',
[KeyTab] = 'Tab',
[KeyBackspace] = 'Backspace',
[KeyReturn] = 'Return',
[KeyEnter] = 'Enter',
[KeyInsert] = 'Insert',
[KeyDelete] = 'Delete',

View File

@ -9,7 +9,7 @@ end
function UIWindow:onKeyPress(keyCode, keyboardModifiers, wouldFilter)
if wouldFilter then return end
if keyboardModifiers == KeyboardNoModifier then
if keyCode == KeyReturn or keyCode == KeyEnter then
if keyCode == KeyEnter then
signalcall(self.onEnter, self)
elseif keyCode == KeyEscape then
signalcall(self.onEscape, self)

View File

@ -93,7 +93,6 @@ function Console.create()
Hotkeys.bindKeyDown('Tab', function() consoleTabBar:selectNextTab() end, consolePanel)
Hotkeys.bindKeyDown('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel)
Hotkeys.bindKeyDown('Enter', Console.sendCurrentMessage, consolePanel)
Hotkeys.bindKeyDown('Return', Console.sendCurrentMessage, consolePanel)
-- apply buttom functions after loaded
connect(consolePanel:getChildById('nextChannelButton'), { onClick = function() consoleTabBar:selectNextTab() end } )

View File

@ -60,7 +60,6 @@ namespace Fw
KeyEscape = 1,
KeyTab = 2,
KeyBackspace = 3,
KeyReturn = 4,
KeyEnter = 5,
KeyInsert = 6,
KeyDelete = 7,

View File

@ -41,7 +41,7 @@ WIN32Window::WIN32Window()
m_keyMap[VK_ESCAPE] = Fw::KeyEscape;
m_keyMap[VK_TAB] = Fw::KeyTab;
m_keyMap[VK_RETURN] = Fw::KeyReturn;
m_keyMap[VK_RETURN] = Fw::KeyEnter;
m_keyMap[VK_BACK] = Fw::KeyBackspace;
m_keyMap[VK_SPACE] = Fw::KeySpace;
@ -162,7 +162,6 @@ WIN32Window::WIN32Window()
m_keyMap[VK_DECIMAL] = Fw::KeyPeriod;
m_keyMap[VK_DIVIDE] = Fw::KeySlash;
m_keyMap[VK_MULTIPLY] = Fw::KeyAsterisk;
m_keyMap[VK_SEPARATOR] = Fw::KeyEnter;
// keypad with numlock off
m_keyMap[VK_NUMPAD0] = Fw::KeyNumpad0;
@ -423,6 +422,51 @@ void WIN32Window::poll()
updateUnmaximizedCoords();
}
Fw::Key WIN32Window::retranslateVirtualKey(WPARAM wParam, LPARAM lParam)
{
if(!(((HIWORD(lParam) >> 8) & 0xFF) & 1)) {
// ignore numpad keys when numlock is on
if((wParam >= VK_NUMPAD0 && wParam <= VK_NUMPAD9) || wParam == VK_SEPARATOR)
return Fw::KeyUnknown;
// retranslate numpad keys
switch(wParam) {
case VK_INSERT:
wParam = VK_NUMPAD0;
break;
case VK_END:
wParam = VK_NUMPAD1;
break;
case VK_DOWN:
wParam = VK_NUMPAD2;
break;
case VK_NEXT:
wParam = VK_NUMPAD3;
break;
case VK_LEFT:
wParam = VK_NUMPAD4;
break;
case VK_CLEAR:
wParam = VK_NUMPAD5;
break;
case VK_RIGHT:
wParam = VK_NUMPAD6;
break;
case VK_HOME:
wParam = VK_NUMPAD7;
break;
case VK_UP:
wParam = VK_NUMPAD8;
break;
case VK_PRIOR:
wParam = VK_NUMPAD9;
break;
}
}
return m_keyMap[wParam];
}
LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
@ -452,11 +496,11 @@ LRESULT WIN32Window::windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
break;
}
case WM_KEYDOWN: {
processKeyDown(m_keyMap[wParam]);
processKeyDown(retranslateVirtualKey(wParam, lParam));
break;
}
case WM_KEYUP: {
processKeyUp(m_keyMap[wParam]);
processKeyUp(retranslateVirtualKey(wParam, lParam));
break;
}
case WM_LBUTTONDOWN: {
@ -641,7 +685,6 @@ void WIN32Window::setTitle(const std::string& title)
void WIN32Window::setMinimumSize(const Size& minimumSize)
{
dump << "set minimum";
m_minimumSize = minimumSize;
}
@ -770,3 +813,4 @@ std::string WIN32Window::getPlatformType()
{
return "WIN32-WGL";
}

View File

@ -43,6 +43,8 @@ class WIN32Window : public PlatformWindow
LRESULT windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
friend class WindowProcProxy;
Fw::Key retranslateVirtualKey(WPARAM wParam, LPARAM lParam);
public:
WIN32Window();

View File

@ -52,7 +52,7 @@ X11Window::X11Window()
m_keyMap[XK_Escape] = Fw::KeyEscape;
m_keyMap[XK_Tab] = Fw::KeyTab;
m_keyMap[XK_Return] = Fw::KeyReturn;
m_keyMap[XK_Return] = Fw::KeyEnter;
m_keyMap[XK_BackSpace] = Fw::KeyBackspace;
m_keyMap[XK_Page_Up] = Fw::KeyPageUp;