diff --git a/modules/addon_terminal/terminal.lua b/modules/addon_terminal/terminal.lua index 5fdb07c0..7bae2ddb 100644 --- a/modules/addon_terminal/terminal.lua +++ b/modules/addon_terminal/terminal.lua @@ -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) diff --git a/modules/core_lib/const.lua b/modules/core_lib/const.lua index 88f0c3fb..ccfe489e 100644 --- a/modules/core_lib/const.lua +++ b/modules/core_lib/const.lua @@ -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', diff --git a/modules/core_widgets/uiwindow.lua b/modules/core_widgets/uiwindow.lua index 1b563ce7..c92b9156 100644 --- a/modules/core_widgets/uiwindow.lua +++ b/modules/core_widgets/uiwindow.lua @@ -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) diff --git a/modules/game_console/console.lua b/modules/game_console/console.lua index d0f86f47..361b6c05 100644 --- a/modules/game_console/console.lua +++ b/modules/game_console/console.lua @@ -38,7 +38,7 @@ local SpeakTypes = { local SayModes = { [1] = { speakTypeDesc = 'whisper', icon = '/core_styles/icons/whisper.png' }, - [2] = { speakTypeDesc = 'say', icon = '/core_styles/icons/say.png' }, + [2] = { speakTypeDesc = 'say', icon = '/core_styles/icons/say.png' }, [3] = { speakTypeDesc = 'yell', icon = '/core_styles/icons/yell.png' } } @@ -87,22 +87,21 @@ function Console.create() Console.addChannel('Default', 0) Console.addTab('Server Log', false) - + Hotkeys.bindKeyDown('Shift+Up', function() navigateMessageHistory(1) end, consolePanel) Hotkeys.bindKeyDown('Shift+Down', function() navigateMessageHistory(-1) end, consolePanel) 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 } ) connect(consolePanel:getChildById('prevChannelButton'), { onClick = function() consoleTabBar:selectPrevTab() end } ) connect(consoleTabBar, { onTabChange = Console.onTabChange }) - + -- tibia like hotkeys Hotkeys.bindKeyDown('Ctrl+O', Game.requestChannels) - Hotkeys.bindKeyDown('Ctrl+E', Console.removeCurrentTab) + Hotkeys.bindKeyDown('Ctrl+E', Console.removeCurrentTab) end function Console.destroy() @@ -131,7 +130,7 @@ end function Console.removeCurrentTab() local tab = consoleTabBar:getCurrentTab() if tab:getText() == "Default" or tab:getText() == "Server Log" then return end - + consoleTabBar:removeTab(tab) end @@ -203,27 +202,27 @@ function Console.sendCurrentMessage() local chatCommandSayMode local chatCommandPrivate local chatCommandPrivateReady - + local chatCommandMessage = message:match("^%#y (.*)") if chatCommandMessage ~= nil then chatCommandSayMode = 'yell' end -- player used yell command message = chatCommandMessage or message - + local chatCommandMessage = message:match("^%#w (.*)") if chatCommandMessage ~= nil then chatCommandSayMode = 'whisper' end -- player used whisper message = chatCommandMessage or message - - local findIni, findEnd, chatCommandInitial, chatCommandPrivate, chatCommandEnd, chatCommandMessage = message:find("([%*%@])(.+)([%*%@])(.*)") + + local findIni, findEnd, chatCommandInitial, chatCommandPrivate, chatCommandEnd, chatCommandMessage = message:find("([%*%@])(.+)([%*%@])(.*)") if findIni ~= nil and findIni == 1 then -- player used private chat command if chatCommandInitial == chatCommandEnd then chatCommandPrivateRepeat = false if chatCommandInitial == "*" then consoleLineEdit:setText('*'.. chatCommandPrivate .. '* ') - end + end message = chatCommandMessage:trim() chatCommandPrivateReady = true end end - + message = message:gsub("^(%s*)(.*)","%2") -- remove space characters from message init if #message == 0 then return end @@ -233,7 +232,7 @@ function Console.sendCurrentMessage() if #messageHistory > MaxHistory then table.remove(messageHistory, 1) end - + -- when talking on server log, the message goes to default channel local name = tab:getText() if name == 'Server Log' then @@ -263,7 +262,7 @@ function Console.sendCurrentMessage() else speaktypedesc = 'privatePlayerToPlayer' end - + local speaktype = SpeakTypesSettings[speaktypedesc] local player = Game.getLocalPlayer() @@ -279,11 +278,11 @@ function Console.sayModeChange(sayMode) if sayMode == nil then sayMode = buttom.sayMode + 1 end - + if sayMode > #SayModes then sayMode = 1 end buttom:setIcon(SayModes[sayMode].icon) - buttom.sayMode = sayMode + buttom.sayMode = sayMode end -- hooked events @@ -311,7 +310,7 @@ local function onOpenPrivateChannel(receiver) end end -local function doChannelListSubmit(channelsWindow) +local function doChannelListSubmit(channelsWindow) local channelListPanel = channelsWindow:getChildById('channelList') local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText() if openPrivateChannelWith ~= '' then @@ -328,7 +327,7 @@ local function onChannelList(channelList) local channelsWindow = displayUI('channelswindow.otui') local channelListPanel = channelsWindow:getChildById('channelList') connect(channelsWindow, { onEnter = function () doChannelListSubmit(channelsWindow) end } ) - + for k,v in pairs(channelList) do local channelId = v[1] local channelName = v[2] @@ -337,7 +336,7 @@ local function onChannelList(channelList) local label = createWidget('ChannelListLabel', channelListPanel) label.channelId = channelId label:setText(channelName) - + label:setPhantom(false) connect(label, { onMouseDoubleClick = function () doChannelListSubmit(channelsWindow) end } ) end diff --git a/src/framework/const.h b/src/framework/const.h index c7f591d0..8684d9e3 100644 --- a/src/framework/const.h +++ b/src/framework/const.h @@ -60,7 +60,6 @@ namespace Fw KeyEscape = 1, KeyTab = 2, KeyBackspace = 3, - KeyReturn = 4, KeyEnter = 5, KeyInsert = 6, KeyDelete = 7, diff --git a/src/framework/platform/win32window.cpp b/src/framework/platform/win32window.cpp index f4ddfdb5..43d76dad 100644 --- a/src/framework/platform/win32window.cpp +++ b/src/framework/platform/win32window.cpp @@ -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"; } + diff --git a/src/framework/platform/win32window.h b/src/framework/platform/win32window.h index 2784ce8d..89bec67c 100644 --- a/src/framework/platform/win32window.h +++ b/src/framework/platform/win32window.h @@ -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(); diff --git a/src/framework/platform/x11window.cpp b/src/framework/platform/x11window.cpp index 24059ea9..0cc92a96 100644 --- a/src/framework/platform/x11window.cpp +++ b/src/framework/platform/x11window.cpp @@ -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;