Announcement

Collapse
No announcement yet.

How to indicate to the user the Caps Lock is on?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to indicate to the user the Caps Lock is on?

    In my setup, one of the dialogs asks for entering a password. It is all astericks, and if the Caps Lock is on, well, that obviously is a problem.

    Is there a way to show the user that the Caps Lock is turned on on the dialog?

  • #2
    Windows Installer provides a balloon with a warning message, if the caps lock key is pressed while the edit field is already being displayed, like so:

    Click image for larger version

Name:	SCRN-2020-12-23-01.png
Views:	135
Size:	17.2 KB
ID:	305877

    However, you will not see this warning, if the caps lock was activated before showing this screen, so this could be a problem like you described. You have a few options here.

    You could check for the state of the caps lock key via a custom action, and show a warning dialog. Here is an example I have just put together as a demonstration:

    Click image for larger version

Name:	SCRN-2020-12-23-03.png
Views:	60
Size:	92.4 KB
ID:	305878

    This uses Dialog.TimedMessage() to show an alert to the user when the first dialog is shown on the screen. Instead of this, you also could show a message in the dialog, but toggling the caps lock key would not automatically hide/show the message.

    If your MSI package comes with a bootstrapper, then you could bundle one of the available tiny command line tools (example), which allow you to turn off the caps lock, so it is guaranteed that the key is inactive at the time when the MSI is started.

    Here is the code I used to check the state of the caps lock key in the example above:

    Code:
    local sState = DLL.CallFunction(_SystemFolder.."\\User32.dll", "GetKeyState", "20", DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);
    if (tonumber(sState) > 0) then
    Dialog.TimedMessage("Warning", "Caps Lock is On!\r\nHaving Caps Lock on may cause you to enter a password incorrectly.\r\nYou should press Caps Lock to turn it off before proceeding.", 5000, MB_ICONEXCLAMATION);
    end
    Ulrich

    Comment


    • #3
      Thanks, perfect!!

      Comment

      Working...
      X