I have a wireless keyboard and mouse that doesn't have any lock indicators, nor any software bundled to provide a visual aid, so I'm making my own.
I got it so that if I click on a notifyIcon it'll list which lock(s) are turned on, but I'd like to make it smarter by alerting me once the locks are engaged.
I found a few items online, but honestly I just want the lock keys, I don't care about any other keyboard presses.
I'm using C# .NET 4, though I can use .NET 4.5 if there's something with that version.
Thanks.
You can use
Control.IsKeyLocked(...)
method as described here: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.iskeylocked%28v=vs.100%29.aspx.The method is available since .NET 2.0 and can be used like this:
This solution doesn't require importing WinApi functions or manually tracking keys states.
Update
In order to track changes of the lock keys, I can suggest You to try one of those solutions:
You will want to register some sort of keyboard hook to listen for the key presses and then retrieve the state of the lock keys like this:
http://blogs.msdn.com/b/toub/archive/2006/05/03/589423.aspx
In addition to the above article, make the below modifications to capture state of the lock keys:
Here is an example for intercepting the keyup on a form or something and tracking it. I changed a local variable, but you can just as easily trigger GUI updates at that time.
Look at the following article on global keyboard events. When one of the locks keys is pressed you could update your UI...
http://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C