Results 1 to 7 of 7

Thread: How do you turn on the cap key?

  1. #1

    Thread Starter
    Hyperactive Member kourosh's Avatar
    Join Date
    Aug 1999
    Location
    Vancouver, British Columbia, Canada
    Posts
    256

    Red face

    I know this should be pretty damn easy. I need to know how to turn on the Cap key through the code. I know I should use setkeyboardstate but I just don't know the rest of the command for this API.

  2. #2
    Lively Member
    Join Date
    Jan 1999
    Location
    Lincolnshire, UK
    Posts
    111
    I don't know the API call for this, but you could cheat by using the following

    On the form, turn on the keypreview property at design time

    in form_keypress enter the following code

    private sub Form_Keypress(KeyAscii as Integer)
    keyascii=asc(ucase(chr(keyascii)))
    end sub

    This will make sure that every letter pressed is in upper case and means that if the user turns off the caps lock when you don't want them to it doesn't matter

    All this does is converts the keyascii value (ASCII value of the key) to the charector (Chr(KeyAscii)), converts this to uppercase (Ucase(chr(keyAscii))) and converts it back to as ASCII code (asc(ucase(chr(keyAscii)))

    All the keypreview property does is makes sure that the forms key events are processed before the controls key events

    Hope this helps

    Chris

  3. #3
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    You can try this

    This code is supposed to do it, but it was not working right for me.

    Code:
    SendKeys "{capslock}"
    Hope this works for ya

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    another way

    'vb6
    'capitalize all small case letters
    '
    If Chr(KeyAscii) >= "a" And Chr(KeyAscii) <= "z" Then
    KeyAscii = KeyAscii - 32
    End If
    '
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282

    Talking API

    here's a routine I use which is originally based upon a KPD Team example :

    Code:
    Option Explicit
    
    Const KB_CAPITAL = &H14
    
    Private Type Key_Bytes
         KeyState(0 To 255) As Byte
    End Type
    
    Private Declare Function GetKeyboardState Lib "user32" (Key_Array As Key_Bytes) As Long
    Private Declare Function SetKeyboardState Lib "user32" (Key_Array As Key_Bytes) As Long
    
    Dim Key_Array As Key_Bytes
    
    Private Sub Main()
    
        CapsOn
        CapsOff
    
    End Sub
    
    Private Sub CapsOn()
        GetKeyboardState Key_Array
        Key_Array.KeyState(KB_CAPITAL) = 1
        SetKeyboardState Key_Array
    End Sub
    
    Private Sub CapsOff()
        GetKeyboardState Key_Array
        Key_Array.KeyState(KB_CAPITAL) = 0
        SetKeyboardState Key_Array
    End Sub
    That's Mr Mullet to you, you mulletless wonder.

  6. #6
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    Taipei
    Posts
    318

    Talking

    Paul,

    How about the NumLock key, what is the constant value?


  7. #7
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282

    Talking More values

    The ones that I can find are :

    Const KB_CAPITAL = &H14
    Const KB_NUMLOCK = &H90
    Const KB_SCROLL = &H91

    Hope this helps.
    That's Mr Mullet to you, you mulletless wonder.

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