how on the caps key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chandru8
    New Member
    • Sep 2007
    • 145

    how on the caps key

    Hi everyone .
    Can anyone help me how on the caps key through coding?
    Last edited by Killer42; Nov 27 '07, 05:41 AM.
  • 9815402440
    New Member
    • Oct 2007
    • 180

    #2
    Hi

    Open new standard exe project. Create a command button (command1) on form1 add following code in the form's code window.

    [CODE=vb]Option Explicit
    ' Declare Type for API call:
    Private Type OSVERSIONINFO
    dwOSVersionInfo Size As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128 ' Maintenance string for PSS usage
    End Type

    ' API declarations:

    Private Declare Function GetVersionEx Lib "kernel32" _
    Alias "GetVersion ExA" _
    (lpVersionInfor mation As OSVERSIONINFO) As Long

    Private Declare Sub keybd_event Lib "user32" _
    (ByVal bVk As Byte, _
    ByVal bScan As Byte, _
    ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

    Private Declare Function GetKeyboardStat e Lib "user32" _
    (pbKeyState As Byte) As Long

    Private Declare Function SetKeyboardStat e Lib "user32" _
    (lppbKeyState As Byte) As Long

    ' Constant declarations:
    Const VK_NUMLOCK = &H90
    Const VK_SCROLL = &H91
    Const VK_CAPITAL = &H14
    Const KEYEVENTF_EXTEN DEDKEY = &H1
    Const KEYEVENTF_KEYUP = &H2
    Const VER_PLATFORM_WI N32_NT = 2
    Const VER_PLATFORM_WI N32_WINDOWS = 1

    Private Sub Command1_Click( )
    Dim o As OSVERSIONINFO
    Dim NumLockState As Boolean
    Dim ScrollLockState As Boolean
    Dim CapsLockState As Boolean

    o.dwOSVersionIn foSize = Len(o)
    GetVersionEx o
    Dim keys(0 To 255) As Byte
    GetKeyboardStat e keys(0)

    ' NumLock handling:
    NumLockState = keys(VK_NUMLOCK )
    If NumLockState <> True Then 'Turn numlock on
    If o.dwPlatformId = VER_PLATFORM_WI N32_WINDOWS Then '=== Win95/98

    keys(VK_NUMLOCK ) = 1
    SetKeyboardStat e keys(0)
    ElseIf o.dwPlatformId = VER_PLATFORM_WI N32_NT Then '=== WinNT
    'Simulate Key Press
    keybd_event VK_NUMLOCK, &H45, KEYEVENTF_EXTEN DEDKEY Or 0, 0
    'Simulate Key Release
    keybd_event VK_NUMLOCK, &H45, KEYEVENTF_EXTEN DEDKEY _
    Or KEYEVENTF_KEYUP , 0
    End If
    End If

    ' CapsLock handling:
    CapsLockState = keys(VK_CAPITAL )
    If CapsLockState <> True Then 'Turn capslock on
    If o.dwPlatformId = VER_PLATFORM_WI N32_WINDOWS Then '=== Win95/98
    keys(VK_CAPITAL ) = 1
    SetKeyboardStat e keys(0)
    ElseIf o.dwPlatformId = VER_PLATFORM_WI N32_NT Then '=== WinNT
    'Simulate Key Press
    keybd_event VK_CAPITAL, &H45, KEYEVENTF_EXTEN DEDKEY Or 0, 0
    'Simulate Key Release
    keybd_event VK_CAPITAL, &H45, KEYEVENTF_EXTEN DEDKEY _
    Or KEYEVENTF_KEYUP , 0
    End If
    End If

    ' ScrollLock handling:
    ScrollLockState = keys(VK_SCROLL)
    If ScrollLockState <> True Then 'Turn Scroll lock on
    If o.dwPlatformId = VER_PLATFORM_WI N32_WINDOWS Then '=== Win95/98
    keys(VK_SCROLL) = 1
    SetKeyboardStat e keys(0)
    ElseIf o.dwPlatformId = VER_PLATFORM_WI N32_NT Then '=== WinNT
    'Simulate Key Press
    keybd_event VK_SCROLL, &H45, KEYEVENTF_EXTEN DEDKEY Or 0, 0
    'Simulate Key Release
    keybd_event VK_SCROLL, &H45, KEYEVENTF_EXTEN DEDKEY _
    Or KEYEVENTF_KEYUP , 0
    End If
    End If
    End Sub[/CODE]


    Regards
    manpreet singh dhillon hoshiarpur
    Last edited by Killer42; Nov 27 '07, 05:42 AM.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Thanks, Manpreet. But it might help if chandru8 could tell us what the actual question is.

      Comment

      • chandru8
        New Member
        • Sep 2007
        • 145

        #4
        Thanks, Manpreet
        thanks for your kindly help

        Comment

        Working...