From bbebc74bdbbdc50f571e9eafca1d45675e58a929 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Sat, 25 Apr 2026 19:27:01 +0300 Subject: [PATCH] fix etcpmon keyboard: move Tab/Enter/Esc from WndProc to message loop pre-translate --- tools/etcpmon/etcpmon_gui.c | 50 ++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/tools/etcpmon/etcpmon_gui.c b/tools/etcpmon/etcpmon_gui.c index c549f8f4..e85abd55 100644 --- a/tools/etcpmon/etcpmon_gui.c +++ b/tools/etcpmon/etcpmon_gui.c @@ -972,31 +972,6 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l return 0; } break; - case WM_KEYDOWN: - if (app) { - switch (wParam) { - case VK_TAB: { - HWND hFocus = GetFocus(); - if (hFocus == app->hEditAddr) { - SetFocus(app->hEditPort); - int len = GetWindowTextLengthA(app->hEditPort); - SendMessageA(app->hEditPort, EM_SETSEL, len, len); - } else if (hFocus == app->hEditPort) { - SetFocus(app->hEditAddr); - int len = GetWindowTextLengthA(app->hEditAddr); - SendMessageA(app->hEditAddr, EM_SETSEL, len, len); - } - return 0; - } - case VK_RETURN: - if (!app->isConnected) OnConnect(app); - return 0; - case VK_ESCAPE: - if (app->isConnected) OnDisconnect(app); - return 0; - } - } - break; case WM_DESTROY: PostQuitMessage(0); @@ -1185,6 +1160,31 @@ int etcpmon_gui_run(struct etcpmon_app* app) { UpdateWindow(app->hWndMain); MSG msg; while (GetMessageA(&msg, NULL, 0, 0)) { + if (msg.message == WM_KEYDOWN && app) { + HWND hFocus = GetFocus(); + if (hFocus == app->hEditAddr || hFocus == app->hEditPort) { + if (msg.wParam == VK_TAB) { + if (hFocus == app->hEditAddr) { + SetFocus(app->hEditPort); + int len = GetWindowTextLengthA(app->hEditPort); + SendMessageA(app->hEditPort, EM_SETSEL, len, len); + } else { + SetFocus(app->hEditAddr); + int len = GetWindowTextLengthA(app->hEditAddr); + SendMessageA(app->hEditAddr, EM_SETSEL, len, len); + } + continue; + } + if (msg.wParam == VK_RETURN) { + if (!app->isConnected) OnConnect(app); + continue; + } + if (msg.wParam == VK_ESCAPE) { + if (app->isConnected) OnDisconnect(app); + continue; + } + } + } TranslateMessage(&msg); DispatchMessageA(&msg); }