diff --git a/Code/KbdHook.cpp b/Code/KbdHook.cpp index 93fdb16..bd8890b 100755 --- a/Code/KbdHook.cpp +++ b/Code/KbdHook.cpp @@ -489,6 +489,7 @@ LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) { // Eat any alphanumeric key if (config.mediaKeysWithCapsLockSpaceArrow && nKey >= 'A' && nKey <= 'Z' && !anyModifierPressed() && capsLockDownLazy()) { + StatusWindow::ShowBlocked(); return 1; } diff --git a/Code/StatusWindow.cpp b/Code/StatusWindow.cpp index a89dc9a..cb2fb78 100755 --- a/Code/StatusWindow.cpp +++ b/Code/StatusWindow.cpp @@ -8,13 +8,21 @@ static bool alreadyRegistered = false; static HWND g_hWnd, g_hStaticText; static char text[100]; +static int windowWidth, windowHeight; static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: - g_hStaticText = CreateWindow("static", text, WS_CHILD | WS_VISIBLE | SS_CENTER | SS_CENTERIMAGE, 0, 0, 200, 50, hWnd, NULL, GetModuleHandle(NULL), 0); + g_hStaticText = CreateWindow("static", text, WS_CHILD | WS_VISIBLE | SS_CENTER | SS_CENTERIMAGE, 0, 0, windowWidth, windowHeight, hWnd, NULL, GetModuleHandle(NULL), 0); break; + //case WM_WINDOWPOSCHANGED: { + // WINDOWPOS *pos = (WINDOWPOS*)lParam; + // printf("SetWindowPos %d %d\n", pos->cx, pos->cy); + // SetWindowPos(hWnd, g_hStaticText, 0, 0, windowWidth, windowHeight, SWP_NOMOVE | SWP_NOZORDER); + // break; + //} + case WM_TIMER: DestroyWindow(hWnd); break; @@ -52,19 +60,23 @@ static ATOM MyRegisterClass(HINSTANCE hInstance) // Needs the text variable to be set to the message text to show // If the text is an empty string, the window is hidden if active / nothing is shown -static void showMessageInternal(int delayMs) { +static void showMessageInternal(int delayMs, int width = 200, int height = 50) { MONITORINFOEX monitorInfo; HMONITOR hMonitor = MonitorFromWindow(GetForegroundWindow(), MONITOR_DEFAULTTOPRIMARY); monitorInfo.cbSize = sizeof(monitorInfo); GetMonitorInfo(hMonitor, &monitorInfo); - const int width = 200, height = 50; bool isEmptyMessage = !text[0]; + if (g_hWnd && (windowWidth != width || windowHeight != height)) { + KillTimer(g_hWnd, 0); + DestroyWindow(g_hWnd); + } + + windowWidth = width, windowHeight = height; if (g_hWnd) { KillTimer(g_hWnd, 0); SetTimer(g_hWnd, 0, delayMs, NULL); - } - else if (!isEmptyMessage) { + } else if (!isEmptyMessage) { if (!alreadyRegistered) MyRegisterClass(GetModuleHandle(NULL)); alreadyRegistered = true; @@ -79,7 +91,8 @@ static void showMessageInternal(int delayMs) { SetWindowPos(g_hWnd, HWND_TOPMOST, (monitorInfo.rcMonitor.right + monitorInfo.rcMonitor.left - width) / 2, (monitorInfo.rcMonitor.bottom + monitorInfo.rcMonitor.top - height) / 2, - width, height, SWP_NOSIZE | SWP_NOZORDER); + width, height, SWP_NOZORDER); + SetWindowPos(g_hWnd, g_hStaticText, 0, 0, windowWidth, windowHeight, SWP_NOMOVE | SWP_NOZORDER); } } @@ -97,6 +110,15 @@ void StatusWindow::showVolume(double volumeLevel) { showMessageInternal(2000); } +void StatusWindow::ShowBlocked() { + MONITORINFOEX monitorInfo; + HMONITOR hMonitor = MonitorFromWindow(GetForegroundWindow(), MONITOR_DEFAULTTOPRIMARY); + monitorInfo.cbSize = sizeof(monitorInfo); + GetMonitorInfo(hMonitor, &monitorInfo); + strcpy_s(text, "CapsLock set; ignoring keystroke"); + showMessageInternal(2000, monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top); +} + void StatusWindow::showMessage(const char *message, int timeToLeaveOpen) { strcpy_s(text, message); showMessageInternal(timeToLeaveOpen); diff --git a/Code/StatusWindow.h b/Code/StatusWindow.h index 7ecbb8c..098f060 100755 --- a/Code/StatusWindow.h +++ b/Code/StatusWindow.h @@ -3,6 +3,7 @@ namespace StatusWindow { extern void showBrightness(int brightnessLevel); extern void showVolume(double volumeLevel); + extern void ShowBlocked(); extern void showMessage(const char *message, int timeToLeaveOpen); extern void hideMessage();