Check for CAPS LOCK = ON

G

Guest

Is it possible to check wether the user of a Worksheet has CAPS LOCK set to
on or off
 
G

Guest

Got it!!!
in Module:

Private Type OSVERSIONINFO
dwOSVersionInfoSize 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 "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

' Constant declarations:
Const VK_CAPITAL = &H14

Function IsCapsLockOn() As Boolean
Dim o As OSVERSIONINFO

o.dwOSVersionInfoSize = Len(o)
GetVersionEx o
Dim keys(0 To 255) As Byte
GetKeyboardState keys(0)
IsCapsLockOn = keys(VK_CAPITAL)
End Function
'******END******


"akyhne" skrev:
 
T

Tom Ogilvy

I think you only need this much of what you posted:



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

' Constant declarations:
Const VK_CAPITAL = &H14

Function IsCapsLockOn() As Boolean

Dim keys(0 To 255) As Byte
GetKeyboardState keys(0)
IsCapsLockOn = keys(VK_CAPITAL)
End Function
 
T

Tom Ogilvy

If you mean run the check each time the user starts typing, I don't believe
there is any built in method or event that would support that. You might be
able to craft something using the Windows API, but that isn't something I
can advise you on.

--
Regards,
Tom Ogilvy



akyhne said:
I run this code on Worksheet.change.
That includes when VBA runs some macros.
How can I tell the Worksheet only to check by userkeystrokes

My code:

If IsCapsLockOn = False Then
MsgBox "Du skal skrive med store bogstaver." & vbln _
& "Slå [Caps Lock] til"
End If




"akyhne" skrev:
Works great!
thanks :))

"Tom Ogilvy" skrev:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top