Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect When Capslock is Changed by User

Status
Not open for further replies.

JTBorton

Technical User
Jun 9, 2008
345
DE
All,

I'm making a user log-in form in excel that interfaces with a background database. I would like the form to signal when capslock is on and off. I have figured out how to test if it is on, but I cannot figure out how to detect when it is changed by the user. I tried inserting some code in the KeyPress event for the userform itself as well as the password entry textbox. Neither seem to work, and placing the code in the textbox KeyPress event doesn't make sense anyway because it would only check capslock when the user is typing in that specific textbox. Does anybody know of a way to detect when capslock is changed by the user?

-Joshua
If it's not broken, it doesn't have enough parts yet.
 
I have figured out how to test if it [Capslock] is on"

And your logic/code to do it is...?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
The problem here is that MSForms, unlike forms in VB6, do not provide a KeyPreview property which allows the form to see all key presses before they are passed to the actual control with focus.

So you basically have two options. Firstly, you can continuously poll the state of the Caps Lock (which is I suspect where Andrzejek is leading), or, secondly, you can insert a keyboard hook which will alert you when the state of Cap Lock changes. For this latter you might want to have a look at my example code in thread222-716589, but note that it needs a little modification to work correctly in a VBA application
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top