VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code is used to change the state of the caps lock so if its on then its turned off and if its

by Stringer (11 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 6th October 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This code is used to change the state of the caps lock so if its on then its turned off and if its off its turned on!! (If there are any

API Declarations


Option Explicit

Private Const VER_PLATFORM_WIN32_NT = 2
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VK_CAPITAL = &H14
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2


Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
End Type

' API declarations:

Private Declare Function GetVersionEx Lib "kernel32" _
Alias "GetVersionExA" _
(lpVersionInformation 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 GetKeyboardState Lib "user32" _
(pbKeyState As Byte) As Long

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

Private Declare Function GetKeyState Lib _
"user32" (ByVal nVirtKey As Long) As Integer

'This code was generated by JOHN STRINGER

Rate This code is used to change the state of the caps lock so if its on then its turned off and if its



    Dim iKeyState As Integer
    iKeyState = GetKeyState(vbKeyCapital)
    CapsLockOn = (iKeyState = 1 Or iKeyState = -127)
End Function
Public Sub ToggleCapsLock(TurnOn As Boolean)

    'To turn capslock on, set turnon to true
    'To turn capslock off, set turnon to false
    
      Dim bytKeys(255) As Byte
      Dim bCapsLockOn As Boolean
      
'Get status of the 256 virtual keys
      GetKeyboardState bytKeys(0)
      
      bCapsLockOn = bytKeys(VK_CAPITAL)
      Dim typOS As OSVERSIONINFO
      
      If bCapsLockOn <> TurnOn Then 'if current state <>
                                     'requested stae
        
       If typOS.dwPlatformId = _
           VER_PLATFORM_WIN32_WINDOWS Then  '=== Win95/98

          bytKeys(VK_CAPITAL) = 1
          SetKeyboardState bytKeys(0)

        Else    '=== WinNT/2000

        'Simulate Key Press
          keybd_event VK_CAPITAL, &H45, _
             KEYEVENTF_EXTENDEDKEY Or 0, 0
        'Simulate Key Release
          keybd_event VK_CAPITAL, &H45, KEYEVENTF_EXTENDEDKEY _
             Or KEYEVENTF_KEYUP, 0
        End If
      End If

     
End Sub

Private Sub Form_load()

If CapsLockOn = False Then
ToggleCapsLock (True)
elseIf CapsLockOn = True Then
ToggleCapsLock (False)
End If

End Sub


Download this snippet    Add to My Saved Code

This code is used to change the state of the caps lock so if its on then its turned off and if its Comments

No comments have been posted about This code is used to change the state of the caps lock so if its on then its turned off and if its . Why not be the first to post a comment about This code is used to change the state of the caps lock so if its on then its turned off and if its .

Post your comment

Subject:
Message:
0/1000 characters