Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Toggling 'Caps Lock' from VBA/Excel 97

8 views
Skip to first unread message

jeremystubbs

unread,
Jun 1, 2000, 3:00:00 AM6/1/00
to
I have seen a similair routine for toggling Num Lock using windows API
calls does anyone know how to do this with Caps Lock. I assume that this
can be done. Any help would be much appreciated.

Thanks,

Jay Stubbs.


pxb

unread,
Jun 6, 2000, 3:00:00 AM6/6/00
to jeremystubbs
Sorry, haven't got anyhting that actually changes the capslock, but this
code here reads the current state. HTH.

Regards,
PhilipB.


Declare Function GetKeyState Lib "USER32" (ByVal nVirtKey As Integer) As
Integer
Const VK_CAPITAL = &H14

Function GetCapsLockState() As Integer ''Returns True if CapsLock is On'
Dim fNumLock As Integer
fNumLock = GetKeyState(VK_CAPITAL)
If fNumLock And 1 Then GetCapsLockState = True
End Function


Sub Test()
If GetCapsLockState Then
MsgBox "CapsLock is ON.", 64, "RSL Business Solutions"
Else
MsgBox "Capslock is OFF.", 64, "RSL Business Solutions"
End If
End Sub

pxb

unread,
Jun 6, 2000, 3:00:00 AM6/6/00
to jeremystubbs

Efstratios Malasiotis

unread,
Jun 6, 2000, 3:00:00 AM6/6/00
to
Hi Jay and Philip,

You could possibly use the following:

(in a standard module:)
---------------------------------------------------------
Declare Function GetKeyboardState Lib "user32.dll" (lpKeyState As Byte) As
Long
Declare Function SetKeyboardState Lib "user32.dll" (lpKeyState As Byte) As
Long

Sub SetCapsLock(CLState As Boolean)
全ub-procedure that sets the CapsLock to True or False
Dim KeyState(0 To 255) As Byte

GetKeyboardState KeyState(0)

If CBool(KeyState(vbKeyCapital)) = True Then
If CLState = True Then
Exit Sub
Else
KeyState(vbKeyCapital) = CByte(Abs(False))
End If
ElseIf CBool(KeyState(vbKeyCapital)) = False Then
If CLState = True Then
KeyState(vbKeyCapital) = CByte(Abs(True))
Else
Exit Sub
End If
End If

SetKeyboardState KeyState(0)
End Sub


Sub Caller1()
Call SetCapsLock(True)
End Sub
-----------------------------------------------------------------------
You can use the procedure calling the Caller1.

The procedure will work regardless of what the respective LED shows, so be
carefull to set it back to the state that the LED shows if you don't want to
confuse your user.


HTH
Regards,
Stratos

0 new messages