https://git.reactos.org/?p=reactos.git;a=commitdiff;h=411a59961002b4e5ec9a7…
commit 411a59961002b4e5ec9a79c3681c7a6e2fff6af7
Author: Bișoc George <fraizeraust99(a)gmail.com>
AuthorDate: Mon Nov 18 21:24:45 2019 +0100
Commit: Hermès BÉLUSCA - MAÏTO <hermes.belusca-maito(a)reactos.org>
CommitDate: Mon Nov 18 21:24:45 2019 +0100
[OSK] Reduce the delay when redrawing LED keyboard resources (#1385)
200 ms would mean that the LEDs redraw each 0,2 second and this adds a slight delay.
This can be seen if you press the Num lock key (for example) many times in a row and the
LED resources won't update instantly. Therefore reducing the value of uElapse should
significantly decrease the delay and the LEDs should update in a realistic way.
Furthermore, before invalidating the LED resource check the toggle state of the keys.
---
base/applications/osk/main.c | 59 ++++++++++++++++++++++++++++++++++++-----
base/applications/osk/precomp.h | 9 +++++++
2 files changed, 62 insertions(+), 6 deletions(-)
diff --git a/base/applications/osk/main.c b/base/applications/osk/main.c
index a467eb24518..7994571dfee 100644
--- a/base/applications/osk/main.c
+++ b/base/applications/osk/main.c
@@ -14,6 +14,13 @@
OSK_GLOBALS Globals;
+OSK_KEYLEDINDICATOR LedKey[] =
+{
+ {VK_NUMLOCK, IDC_LED_NUM, 0x0145, FALSE},
+ {VK_CAPITAL, IDC_LED_CAPS, 0x013A, FALSE},
+ {VK_SCROLL, IDC_LED_SCROLL, 0x0146, FALSE}
+};
+
/* FUNCTIONS ******************************************************************/
/***********************************************************************
@@ -237,7 +244,7 @@ int OSK_DlgInitDialog(HWND hDlg)
Globals.hBrushGreenLed = CreateSolidBrush(RGB(0, 255, 0));
/* Set a timer for periodics tasks */
- Globals.iTimer = SetTimer(hDlg, 0, 200, NULL);
+ Globals.iTimer = SetTimer(hDlg, 0, 50, NULL);
return TRUE;
}
@@ -281,6 +288,29 @@ int OSK_DlgClose(void)
return TRUE;
}
+/***********************************************************************
+ *
+ * OSK_RefreshLEDKeys
+ *
+ * Updates (invalidates) the LED icon resources then the respective
+ * keys (Caps Lock, Scroll Lock or Num Lock) are being held down
+ */
+VOID OSK_RefreshLEDKeys(VOID)
+{
+ INT i;
+ BOOL bKeyIsPressed;
+
+ for (i = 0; i < _countof(LedKey); i++)
+ {
+ bKeyIsPressed = (GetAsyncKeyState(LedKey[i].vKey) & 0x8000) != 0;
+ if (LedKey[i].bWasKeyPressed != bKeyIsPressed)
+ {
+ LedKey[i].bWasKeyPressed = bKeyIsPressed;
+ InvalidateRect(GetDlgItem(Globals.hMainWnd, LedKey[i].DlgResource), NULL,
FALSE);
+ }
+ }
+}
+
/***********************************************************************
*
* OSK_DlgTimer
@@ -298,10 +328,11 @@ int OSK_DlgTimer(void)
Globals.hActiveWnd = hWndActiveWindow;
}
- /* Always redraw leds because it can be changed by the real keyboard) */
- InvalidateRect(GetDlgItem(Globals.hMainWnd, IDC_LED_NUM), NULL, TRUE);
- InvalidateRect(GetDlgItem(Globals.hMainWnd, IDC_LED_CAPS), NULL, TRUE);
- InvalidateRect(GetDlgItem(Globals.hMainWnd, IDC_LED_SCROLL), NULL, TRUE);
+ /*
+ Update the LED key indicators accordingly to their state (if one
+ of the specific keys is held down).
+ */
+ OSK_RefreshLEDKeys();
return TRUE;
}
@@ -320,6 +351,7 @@ BOOL OSK_DlgCommand(WPARAM wCommand, HWND hWndControl)
BOOL bKeyDown;
BOOL bKeyUp;
LONG WindowStyle;
+ INT i;
/* FIXME: To be deleted when ReactOS will support WS_EX_NOACTIVATE */
if (Globals.hActiveWnd)
@@ -357,8 +389,23 @@ BOOL OSK_DlgCommand(WPARAM wCommand, HWND hWndControl)
bKeyUp = TRUE;
}
- /* Extended key ? */
+ /* Get the key from dialog control key command */
ScanCode = wCommand;
+
+ /*
+ The user could've pushed one of the key buttons of the dialog that
+ can trigger particular function toggling (Caps Lock, Num Lock or Scroll Lock).
Update
+ (invalidate) the LED icon resources accordingly.
+ */
+ for (i = 0; i < _countof(LedKey); i++)
+ {
+ if (LedKey[i].wScanCode == ScanCode)
+ {
+ InvalidateRect(GetDlgItem(Globals.hMainWnd, LedKey[i].DlgResource), NULL,
FALSE);
+ }
+ }
+
+ /* Extended key ? */
if (ScanCode & 0x0200)
bExtendedKey = TRUE;
else
diff --git a/base/applications/osk/precomp.h b/base/applications/osk/precomp.h
index c1e7e50543d..e2503f787e4 100644
--- a/base/applications/osk/precomp.h
+++ b/base/applications/osk/precomp.h
@@ -46,6 +46,14 @@ typedef struct
INT PosY;
} OSK_GLOBALS;
+typedef struct
+{
+ INT vKey;
+ INT DlgResource;
+ WORD wScanCode;
+ BOOL bWasKeyPressed;
+} OSK_KEYLEDINDICATOR;
+
/* PROTOTYPES *****************************************************************/
/* main.c */
@@ -59,6 +67,7 @@ INT_PTR APIENTRY OSK_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM
lParam);
LRESULT APIENTRY OSK_ThemeHandler(HWND hDlg, NMCUSTOMDRAW *pNmDraw);
int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int);
VOID OSK_RestoreDlgPlacement(HWND hDlg);
+VOID OSK_RefreshLEDKeys(VOID);
/* settings.c */
BOOL LoadDataFromRegistry(VOID);