Results 1 to 9 of 9

Thread: caps lock

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Location
    Bosnia and Herzegovina
    Posts
    65

    caps lock

    Hi,

    How to enable caps locks in my app. so that caps is always on in my app. and that the user cannot turn it off.

  2. #2
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: caps lock

    Turn On Caps Lock : http://support.microsoft.com/?id=177674

    User cannot turn it off : Don't know. Here is an alternative,
    set the form's KeyPreview = True at design time.
    Then in the form's Form_KeyDown event turn on the Caps Lock.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  3. #3
    Hyperactive Member capsulecorpjx's Avatar
    Join Date
    May 2005
    Location
    Renton, WA
    Posts
    288

    Re: caps lock

    Quote Originally Posted by greenba
    Hi,

    How to enable caps locks in my app. so that caps is always on in my app. and that the user cannot turn it off.
    WHY WOULD YOU WANT TO DO THAT?
    "I like to run on treadmills, because at least I know I'm getting nowhere."
    - Me

  4. #4
    Hyperactive Member guyvdn's Avatar
    Join Date
    Oct 2002
    Location
    Belgium
    Posts
    336

    Re: caps lock

    It can be done like this

    VB Code:
    1. Const VK_CAPITAL = &H14
    2. Const VK_NUMLOCK = &H90
    3. Const VK_SCROLL = &H91
    4.  
    5. Private Type KeyboardBytes
    6.      kbByte(0 To 255) As Byte
    7. End Type
    8. Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
    9. Private Declare Function SetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long
    10. Dim kbArray As KeyboardBytes
    11.  
    12. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    13.     If KeyCode = vbKeyCapital Then
    14.         TurnOn VK_CAPITAL
    15.     End If
    16. End Sub
    17.  
    18. Private Sub Form_Load()
    19.     TurnOn VK_CAPITAL
    20. End Sub
    21.  
    22. Private Sub TurnOn(vkKey As Long)
    23.     'Change a key
    24.     kbArray.kbByte(vkKey) = 1
    25.     'Set the keyboard state
    26.     SetKeyboardState kbArray
    27. End Sub
    To deny our own impulses is to deny the very thing that makes us human

  5. #5
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: caps lock

    @guyvdn
    The problem with SetKeyboardState is, it will set the Caps Lock state correctly, but it will not turn on keyboard LED on Win2000/XP systems. It may confuse the user.

    On Win200/XP systems, we need to simulate a keypress using keybd_event.

    Last edited by iPrank; Feb 9th, 2006 at 10:52 PM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  6. #6
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: caps lock

    is there really a need for you to have the caps lock always on. if its just for a few textboxes, used the keypress event of the textbox

    VB Code:
    1. private sub text1_keypress(keyascii as integer)
    2.     keyascii = asc(ucase(chr(keyascii)))
    3. end sub
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  7. #7
    Hyperactive Member guyvdn's Avatar
    Join Date
    Oct 2002
    Location
    Belgium
    Posts
    336

    Re: caps lock

    Quote Originally Posted by iPrank
    @guyvdn
    The problem with SetKeyboardState is, it will set the Caps Lock state correctly, but it will not turn on keyboard LED on Win2000/XP systems. It may confuse the user.
    I didn’t notice that, I have a wireless keyboard and the leds are on a docking station that’s urm somewhere on my desk

    Quote Originally Posted by d3gerald
    is there really a need for you to have the caps lock always on. if its just for a few textboxes, used the keypress event of the textbox
    If you set keypreview of the form to true you can use the keypress event of the form. You only have to write the code once and it will work for all the controls. But the keyboard LED will also not be turned on.
    To deny our own impulses is to deny the very thing that makes us human

  8. #8
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: caps lock

    PS2 or USB keyboard ? Mine is a plain PS2.
    May be other members can give more different 'input'.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  9. #9
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: caps lock

    Quote Originally Posted by greenba
    Hi,

    How to enable caps locks in my app. so that caps is always on in my app. and that the user cannot turn it off.
    I wouldn't do this. I wouldn't want Users to get annoyed when they CAPS lock turned on even when they didn't do anything. If you actually need UpperCase characters in your application, then you can always use UCase$ to convert the text in UpperCase. But doing unexpected is not what Users like.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width