Caps Key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sengmca
    New Member
    • Feb 2007
    • 7

    Caps Key

    hi friends,
    this is senny, here i have to solve my pbm thrugh ur kind suggestion.In my project ,i have to restrict the user to use "CAPS KEY" like when we go to login if caps pressed the msbbox is come with msg "caps key pressed".

    thanks in advance
    senny
  • ansumansahu
    New Member
    • Mar 2007
    • 149

    #2
    Originally posted by sengmca
    hi friends,
    this is senny, here i have to solve my pbm thrugh ur kind suggestion.In my project ,i have to restrict the user to use "CAPS KEY" like when we go to login if caps pressed the msbbox is come with msg "caps key pressed".

    thanks in advance
    senny
    Hi ,

    If the CAPS LOCK is on and one trys to enter data then we can trap the Ascii code of the keys pressed and then display an message that CAPS letters are not allowed.

    thanks
    ansuman

    Comment

    • cmrhema
      Contributor
      • Jan 2007
      • 375

      #3
      Originally posted by ansumansahu
      Hi ,

      If the CAPS LOCK is on and one trys to enter data then we can trap the Ascii code of the keys pressed and then display an message that CAPS letters are not allowed.

      thanks
      ansuman
      As put up by ansuman try trapping the ascii code of keys
      A carries an ascii code of 65 it continues till Z which has the ascii code of 90
      Put an condition in keypress event
      If KeyAscii >= 65 And KeyAscii <= 90 Then
      Text1.Locked = True
      Msgbox "CAPS ON"
      Else
      Text1.Locked = False
      End If

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by sengmca
        hi friends,
        this is senny, here i have to solve my pbm thrugh ur kind suggestion.In my project ,i have to restrict the user to use "CAPS KEY" like when we go to login if caps pressed the msbbox is come with msg "caps key pressed".
        Have a look at this link... How To Toggle the NUM LOCK, CAPS LOCK, and SCROLL LOCK Keys. Specifically, I think you'll be interested in the GetKeyboardStat e function.

        Comment

        • ChillUmesh
          New Member
          • Feb 2007
          • 20

          #5
          Originally posted by cmrhema
          As put up by ansuman try trapping the ascii code of keys
          A carries an ascii code of 65 it continues till Z which has the ascii code of 90
          Put an condition in keypress event
          If KeyAscii >= 65 And KeyAscii <= 90 Then
          Text1.Locked = True
          Msgbox "CAPS ON"
          Else
          Text1.Locked = False
          End If

          THIS DOESN'T WORK IF USER IS TYPING BYPRESSING SHIFT KEY

          Comment

          • cmrhema
            Contributor
            • Jan 2007
            • 375

            #6
            Originally posted by ChillUmesh
            THIS DOESN'T WORK IF USER IS TYPING BYPRESSING SHIFT KEY
            This WORKS even if user is typing by pressing shift key
            Here the key Caps or Shift(in my code) is immaterial. All the code does is traps the ascii value in the IFfunction . So irrespective of of SHIFT or CAPS it will work.
            I have verified it.

            Comment

            • SammyB
              Recognized Expert Contributor
              • Mar 2007
              • 807

              #7
              Originally posted by sengmca
              hi friends,
              this is senny, here i have to solve my pbm thrugh ur kind suggestion.In my project ,i have to restrict the user to use "CAPS KEY" like when we go to login if caps pressed the msbbox is come with msg "caps key pressed".

              thanks in advance
              senny
              Senny, Killer is absolutely correct: For VBA and VB6, you need to use the GetKeyboardStat e api. (thanks, Killer, for the link! I added it to Favorites)

              However, it is much easier in VB.NET, you just use the Control class:
              Code:
              If Control.IsKeyLocked(Keys.CapsLock) Then _
              	MsgBox("CAPS LOCK is ON!", MsgBoxStyle.Exclamation)
              See, VB.DotNet really is nicer! ;) --Sam

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by cmrhema
                This WORKS even if user is typing by pressing shift key
                Here the key Caps or Shift(in my code) is immaterial. All the code does is traps the ascii value in the IFfunction . So irrespective of of SHIFT or CAPS it will work.
                I have verified it.
                I think the basic problem here is that it won't tell you if the capslock key is down. All it will tell you is that an uppercase key was typed - however that happened.

                The original poster was not looking for how to tell if an uppercase letter is typed. They wanted to be able to warn that the capslock is down - you know, the way Windows XP does at password entry.

                Comment

                • cmrhema
                  Contributor
                  • Jan 2007
                  • 375

                  #9
                  Originally posted by Killer42
                  I think the basic problem here is that it won't tell you if the capslock key is down. All it will tell you is that an uppercase key was type - however that happened.

                  The original poster was not looking for how to tell if an uppercase letter is typed. They wanted to be able to warn that the capslock is down - you know, the way Windows XP does at password entry.
                  I understood now. Went through your link. Wonderful article
                  Thanks killer

                  Comment

                  Working...