How to set and unset caps lock

what i want is some code that i can run at the start of the program to set caps lock to on and also some code to set it off as the program ends.
kplonkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

caraf_gCommented:
Check out
http://homepage.eircom.net/~carafa/VBSamples/VBAll/NumLock.zip
This sample shows you how to check and toggle Caps Lock, Num Lock AND Scroll lock.

Good luck!

Pino
0
ajsriramCommented:
Public Const VK_CAPITAL = &H14


Public Type KeyboardBytes
         kbByte(0 To 255) As Byte
    End Type
    Public kbArray As KeyboardBytes


Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Long


Public Declare Function GetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long


Public Declare Function SetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long
                                    
 


On  form, add a 3 command buttons (cmdToggle, cmdTurnOff, cmdTurnOff) and a label. Add the following code to the form:


Private Function CapsLock() As Integer
CapsLock
= GetKeyState(VK_CAPITAL) And 1 = 1
End Function



Private Sub Form_Load()

If CapsLock() = 1 Then Label1 = "On" Else Label1 = "Off"
End Sub



Private Sub cmdToggle_Click()
GetKeyboardState kbArray
kbArray.kbByte(VK_CAPITAL) =
IIf(kbArray.kbByte(VK_CAPITAL) = 1, 0, 1)
SetKeyboardState kbArray
Label1 =
IIf(CapsLock() = 1, "On", "Off")
End Sub



Private Sub cmdTurnOn_Click()
GetKeyboardState kbArray
kbArray.kbByte(VK_CAPITAL) = 1
SetKeyboardState kbArray
Label1 =
IIf(CapsLock() = 1, "On", "Off")
End Sub



Private Sub cmdTurnOff_Click()
GetKeyboardState kbArray
kbArray.kbByte(VK_CAPITAL) = 0
SetKeyboardState kbArray
Label1 =
IIf(CapsLock() = 1, "On", "Off")
End Sub
 
0
caraf_gCommented:
Yes, ajsriram, that's exactly what I'm doing in my example.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

amebaCommented:
No, it isn't the same - you are using keybd_event (which works OK).

ajsriram used SetKeyboardState which has some problems (leaving lights in wrong state when focus goes to other app). Most of the VB sites have this incorrect (Win 3.1) code.
0
kplonkAuthor Commented:
the reason that i rejected this was the same as the one the was pointed out by ameba thanks for all the help though. amber as i used your code or atlest some of it if you repost as an answer you can have the points.  see ya later kieran
0
amebaCommented:
kplonk, I think you can "accept comment as an answer" - new feature on EE.

Happy New Year!
0
caraf_gCommented:
Happy New Year everyone
0
AndySulzCommented:
dim x as vbkeycodeconstant
x = vbKeyCapital
sendkeys x
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
caraf_gCommented:
A message from the future:
Eejit.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.