Announcement

Collapse
No announcement yet.

How to programatically Disable Caps Lock Pop-up Notification in Windows

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

  • How to programatically Disable Caps Lock Pop-up Notification in Windows

    Hi All

    I have a password entry program, I don't want users to be alerted with message " Caps lock is on " whenever the Caps lock
    is pressed accidentally or otherwise. How to programatically Disable Caps Lock Pop-up Notification in Windows?

    there is a reference below but it involves writing into registry ( a method I wish to avoid ).

    https://www.top-password.com/blog/di...n%20click%20OK.

  • #2
    Tim,
    Likely you would want to subclass the control to provide you with that ability.

    Comment


    • #3
      Thank you Jim and this is my program listing
      Code:
      ' password prog.bas
      
      #COMPILE EXE
      #DIM ALL
      
      #INCLUDE "Win32API.inc"
      
      
       %IDC_TextBox = 500
       %IDC_BtnC = 501
       %IDC_BtnCC = 502
      
      
      
      
      ' For the Machine IDs
         GLOBAL cstRelDate , cstHDserial ,cstVolsn  , cstMBSNumb AS STRING
         GLOBAL cstMac  AS STRING  , cstIP AS STRING
      
      
         GLOBAL hDlg AS DWORD, Hkl AS LONG
         GLOBAL EChar   AS STRING
         GLOBAL Flagmc AS LONG
      
      
      FUNCTION PBMAIN() AS LONG
         EChar = "*"
         Hkl = 1   ' Always hidden
      
       '  clear off all clipboard memories when starting a new dialog
          CLIPBOARD RESET
      
      
      
         DIALOG NEW PIXELS, 0, "",305,310,115,55, %WS_VISIBLE OR %WS_POPUP TO hDlg
         DIALOG SET COLOR hDlg,-1, %RGB_LIGHTYELLOW
      
      
         CONTROL ADD BUTTON, hDlg, %IDC_BtnC, "Check",10,30,50,20
         CONTROL ADD BUTTON, hDlg, %IDC_BtnCC, "Ex", 90,30,20,20
      
        CONTROL ADD TEXTBOX, hDlg, %IDC_TextBox, "", 10,5,100,20
      
      ' Ensure that the textbox entry is hidden
        SendMessage GetDlgItem(hDlg,%IDC_TextBox), %EM_SetPassWordChar, IIF(Hkl, ASC(EChar), 0), 0
        CONTROL SET FOCUS hDlg, %IDC_TextBox
      
         DIALOG SHOW MODAL hDlg CALL DlgProc
      END FUNCTION
      
      
      CALLBACK FUNCTION DlgProc() AS LONG
         LOCAL tempst  AS STRING
      
        SELECT CASE CB.MSG
      
           CASE %WM_COMMAND
              IF CB.CTL = %IDC_BtnC AND CB.CTLMSG = %BN_CLICKED THEN
                ' check password button
                tempst = ""
                SendMessage GetDlgItem(hDlg,%IDC_TextBox), %EM_SetPassWordChar, IIF(Hkl, ASC(EChar), 0), 0
                CONTROL REDRAW hDlg, %IDC_TextBox
                CONTROL GET TEXT hDlg, %IDC_TextBox TO tempst
                IF tempst ="c0rr3ct" THEN
                    ? " correct password "
                    Flagmc = 1
                ELSE
                    ? " wrong password "
                    DIALOG END hDlg  , 0
                END IF
              END IF
      
              IF CB.CTL = %IDC_BtnCC AND CB.CTLMSG = %BN_CLICKED THEN
             ' for the exit button
               CLIPBOARD RESET
               tempst = ""
               CONTROL SET TEXT hDlg, %IDC_TextBox, tempst
               DIALOG END hDlg  , 0
              END IF
      
      
      
      
          CASE %WM_SysCommand
               IF ((CB.WPARAM AND &HFFF0) = %SC_CLOSE)  THEN
                     'trap Alt-F4, X-button, WindowMenu/Close
                    'Blocks Alt-F4 from closing the program
                    'or close at the tray
                     FUNCTION = 1
               END IF
      
      
         END SELECT
      
      END FUNCTION

      Comment


      • #4
        How do I subclass

        also I bet %EM_SetPassWordChar style could have some bearing on this "caps lock" notification?

        Comment


        • #5
          Originally posted by Tim Lakinir View Post
          How do I subclass

          also I bet %EM_SetPassWordChar style could have some bearing on this "caps lock" notification?
          Does not look like it does.

          https://docs.microsoft.com/en-us/win...etpasswordchar

          Cheers,

          Dale

          Comment


          • #6
            Tim,
            I tried your app in #3 but did not see a " Caps lock is on " notification message at any time. Windows 10 2004.

            Comment


            • #7
              Originally posted by Jim Fritts View Post
              Tim,
              I tried your app in #3 but did not see a " Caps lock is on " notification message at any time. Windows 10 2004.
              That is his password code. He wants to add disabling of caps lock to it to make things easier for his users.
              Dale

              Comment


              • #8
                I think you should read his post again.
                I have a password entry program, I don't want users to be alerted with message " Caps lock is on " whenever the Caps lock is pressed accidentally or otherwise. How to programatically Disable Caps Lock Pop-up Notification in Windows?
                I say again, I ran his code and received no notifications when cycling the Caps lock. That is why I specified my system configuration. Windows 10 2004.

                Comment


                • #9
                  Originally posted by Jim Fritts View Post
                  I think you should read his post again.

                  I say again, I ran his code and received no notifications when cycling the Caps lock. That is why I specified my system configuration. Windows 10 2004.
                  I think YOU should read his post for the first time. He said "How to programatically Disable Caps Lock Pop-up Notification in Windows?" He wants disabling, not just a warning to add to his code. So of course you received no warnings; there are none in the code, if you had bothered to read the code!

                  Tim, when you get a chance, please restate.
                  Dale

                  Comment


                  • #10
                    Dale, Jim.

                    I think you guys are talking past each other

                    As I understand it, on his PC, Tim is getting a system notification when he enters a textbox which has the password style if CapsLock is on. He wants to disable that notification.

                    I think I misread it as well. see next post

                    Comment


                    • #11
                      The Capslock popup appears to be manufacturer specific according to what I find on the intertubes. There should be a system configuration option for it if it is implemented.

                      https://www.top-password.com/blog/di...on-in-windows/

                      Comment


                      • #12
                        there is a reference below but it involves writing into registry ( a method I wish to avoid ).
                        The instructions on linked page have REGEDIT.
                        Dale

                        Comment


                        • #13
                          Maybe misunderstand, but if task is to prevent CapsLock from being triggered in a program, one can use a timer and monitor %VK_CAPITAL GetKeyState - like in code below:
                          '
                          Code:
                          #COMPILE EXE
                          #INCLUDE "WIN32API.INC"
                          
                          '====================================================================
                          FUNCTION PBMAIN () AS LONG
                            LOCAL hDlg AS DWORD
                            DIALOG NEW 0, "No CapsLock",,, 220, 140, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg
                            DIALOG SHOW MODAL hDlg CALL DlgProc
                          END FUNCTION
                          
                          '====================================================================
                          CALLBACK FUNCTION DlgProc() AS LONG
                            STATIC hTimer AS DWORD
                          
                            SELECT CASE AS LONG CB.MSG
                            CASE %WM_INITDIALOG
                                hTimer = SetTimer(CB.HNDL, 1, 10, 0) ' start timer
                          
                            CASE %WM_Destroy
                                IF hTimer THEN KillTimer CB.HNDL, hTimer ' kill timer
                          
                            CASE %WM_TIMER
                                IF GetForegroundWindow = CB.HNDL AND _
                                   (GetKeyState(%VK_CAPITAL) AND &H1) THEN
                                   Keybd_Event %VK_CAPITAL, 0, 0, 0
                                   Keybd_Event %VK_CAPITAL, 0, %KEYEVENTF_KEYUP, 0
                                END IF
                          
                            END SELECT
                          END FUNCTION
                          '

                          Comment


                          • #14
                            I have the Logitech Software installed for my Logitech Keyboard and Logitech Mouse on Windows 10.

                            When I press the caps lock key,

                            Click image for larger version

Name:	caps1.png
Views:	53
Size:	41.9 KB
ID:	797474

                            an image briefly appears on the screen with the Caps Lock status.

                            Click image for larger version

Name:	caps2.png
Views:	49
Size:	37.2 KB
ID:	797475

                            Each keyboard vendor does this differently, so to remove this status message programmatically would be different for each keyboard vendor.

                            Joe

                            Comment


                            • #15
                              Thank you Everyone, this solves the case. It seems that "Caps lock" notifications are based on hardware ( as Joe stated above)
                              as I tried the program in post #3 on different pcs with Win 7 through win 10. Sometimes gotten notification and at most time none.

                              Comment


                              • #16
                                Thank you Sir Borje, I have tested out your program, it comes in very handy and this is the modified version
                                Code:
                                ' Prevent Caps.bas
                                'https://forum.powerbasic.com/forum/user-to-user-discussions/powerbasic-for-windows/797456-how-to-programatically-disable-caps-lock-pop-up-notification-in-windows?p=797470#post797470
                                
                                ' task is to prevent CapsLock from being triggered in a
                                ' program, one can use a timer and monitor %VK_CAPITAL GetKeyState
                                
                                ' Users can click Capslock On but would not be able to enter capital letters
                                ' into the textbox
                                ' However it does not affect other programs such as notepad while
                                ' running in the same computer at the same time
                                
                                ' Many thanks to Sir Boyle
                                
                                #COMPILE EXE
                                #INCLUDE "WIN32API.INC"
                                
                                %IDC_TextBox = 500
                                 %IDC_BtnC = 501
                                 GLOBAL hDlg AS DWORD
                                
                                '====================================================================
                                FUNCTION PBMAIN () AS LONG
                                
                                  DIALOG NEW 0, "Prevent CapsLock",,, 220, 140, %WS_CAPTION OR %WS_SYSMENU, 0 TO hDlg
                                
                                   CONTROL ADD BUTTON, hDlg, %IDC_BtnC, "Check",10,50,50,20
                                
                                  CONTROL ADD TEXTBOX, hDlg, %IDC_TextBox, "", 10,5,100,20
                                
                                
                                  DIALOG SHOW MODAL hDlg CALL DlgProc
                                END FUNCTION
                                
                                '====================================================================
                                CALLBACK FUNCTION DlgProc() AS LONG
                                  STATIC hTimer AS DWORD
                                  LOCAL tempst AS STRING
                                
                                  SELECT CASE AS LONG CB.MSG
                                  CASE %WM_INITDIALOG
                                      hTimer = SetTimer(CB.HNDL, 1, 10, 0) ' start timer
                                
                                   CASE %WM_COMMAND
                                        IF CB.CTL = %IDC_BtnC AND CB.CTLMSG = %BN_CLICKED THEN
                                          ' check data entry button
                                          tempst = ""
                                          CONTROL GET TEXT hDlg, %IDC_TextBox TO tempst
                                           ?  tempst
                                        END IF
                                
                                
                                
                                  CASE %WM_DESTROY
                                      IF hTimer THEN
                                          KillTimer CB.HNDL, hTimer ' kill timer
                                      END IF
                                
                                  CASE %WM_TIMER
                                      IF GetForegroundWindow = CB.HNDL AND _
                                         (GetKeyState(%VK_CAPITAL) AND &H1) THEN
                                         Keybd_Event %VK_CAPITAL, 0, 0, 0
                                         Keybd_Event %VK_CAPITAL, 0, %KEYEVENTF_KEYUP, 0
                                      END IF
                                
                                  END SELECT
                                END FUNCTION

                                Comment


                                • #17
                                  Thank you Everyone, this solves the case. It seems that "Caps lock" notifications are based on hardware ( as Joe stated above) as I tried the program in post #3 on different pcs with Win 7 through win 10. Sometimes gotten notification and at most time none.
                                  Yup, based on hardware and drivers for those devices.

                                  Comment


                                  • #18
                                    How do I subclass
                                    You could start by searching keyword "subclass" here in the message title.

                                    But better probably if you first understand what subclassing is.

                                    What it is, is, adding your own routine to intercept and process certain windows notification messages so you can add, change or delete the default default Windows' processing of that message.

                                    FOR EXAMPLE... When the <ENTER> key is pressed, the default Windows' action on a DIALOG is to "pretend it was a 'click' on the default button control.' (Not the same on a non-dialog window); some programmers instead want <ENTER> to mean "accept the value entered in this edit control and go (set focus) to the next control on the screen. Subclassing is used to change the default behavior for the the WM_CHAR notification message sent to the dialog when the user presses <ENTER>. . There are multiple examples of this very "default dehavior change' here .. which will also show you there is more than one way to accomplish this.

                                    MCM
                                    Michael Mattias
                                    Tal Systems Inc. (retired)
                                    Racine WI USA
                                    [email protected]
                                    http://www.talsystems.com

                                    Comment


                                    • #19
                                      NOTE:
                                      If the device is using Windows drivers rather than OEM drivers then the typical built-in manufacture notifications may or may not be replicated for said device.

                                      Comment


                                      • #20
                                        I also like Borje's solution here because it only affects THIS program.

                                        Since the keyboard is a shared resource, I'd be chary of changing a system setting (e.g. via writing to the registry) since that might affect ALL programs running on the system!
                                        Michael Mattias
                                        Tal Systems Inc. (retired)
                                        Racine WI USA
                                        [email protected]
                                        http://www.talsystems.com

                                        Comment

                                        Working...
                                        X