Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6604655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:11:09+00:00 2026-05-25T19:11:09+00:00

You may find if the CapsLock key has been pressed subscribing to the KeyDown/KeyUp

  • 0

You may find if the CapsLock key has been pressed subscribing to the KeyDown/KeyUp event. And then toggle the state of the CapsLock based on that input. The problem with this approach is that you need the initial state of the CapsLock key to start toggling that.

One application of this could be giving the user a notification on a Login Page (this is what i need).

By the way i’m using Silverlight 5.

EDIT

The solution posted here says:

You can however find out if Capslock is on by making use of
KeyEventArgs.PlatformKeyCode that’s actually send at onKeyDown.You can
look up the Virtual Key-code for capslock in here:
http://msdn.microsoft.com/en-us/library/ms927178.aspx

With this solution you can’t determine the CapsLock state, because KeyEventArgs.PlatformKeyCode returns “an integer value that represents the key that is pressed or released (depending on which event is raised)”. So if CapsLock is On and Key A is pressed then KeyEventArgs.PlatformKeyCode = 65, and on the other hand if CapsLock is off and Key A is pressed then KeyEventArgs.PlatformKeyCode = 65.

In other words you can’t determine if the CapsLock is enabled or not based on the KeyEventArgs.PlatformKeyCode property.


The answer to this question also seems to have a solution, it checks two things:

  1. the letter typed is Upper Case and Shift isn’t pressed
  2. the letter typed is Lower Case and Sift is pressed

Both of this cases implies that the CapsLock is On, but there is also a problem with this solution, given a KeyEventArgs you can know the pressed key in the keyboard but can’t know the Char outputted by that key.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:11:09+00:00Added an answer on May 25, 2026 at 7:11 pm

    I’d suggest using a Behavior for this detection since you can hook into the PasswordChanged and KeyDown events to determine if the Caps Lock is on. Here is a quick behavior I wrote to detect if the Caps Lock is on. You can bind to the CapsLockOn behavior and use something like a data state behavior to hide/show your warning message.

    public class DetectCapsLockBehavior : Behavior<PasswordBox>
    {
        private int _lastKey;
        private ModifierKeys _modifiers;
    
        [Category("Settings")]
        public bool CapsLockOn
        {
            get { return (bool)GetValue(CapsLockOnProperty); }
            set { SetValue(CapsLockOnProperty, value); }
        }
    
        public static readonly DependencyProperty CapsLockOnProperty = DependencyProperty.Register("CapsLockOn", typeof(bool), typeof(DetectCapsLockBehavior), new PropertyMetadata(null));
    
        protected override void OnAttached()
        {
            AssociatedObject.PasswordChanged += new RoutedEventHandler(AssociatedObject_PasswordChanged);
            AssociatedObject.KeyDown += new KeyEventHandler(AssociatedObject_KeyDown);
        }
    
        void AssociatedObject_KeyDown(object sender, KeyEventArgs e)
        {
            _lastKey = e.PlatformKeyCode;
            _modifiers = Keyboard.Modifiers;
        }
    
        void AssociatedObject_PasswordChanged(object sender, RoutedEventArgs e)
        {
            if (_lastKey >= 0x41 && _lastKey <= 0x5a)
            {
                var lastChar = AssociatedObject.Password.Last();
                if (_modifiers != ModifierKeys.Shift)
                {
                    CapsLockOn = char.ToLower(lastChar) != lastChar;
                }
                else
                {
                    CapsLockOn = char.ToUpper(lastChar) != lastChar;
                }
            }
        }
    }
    

    NOTE: This is sample code, so there could be bugs. Just trying to demonstrate how it could be done.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I may be doing something wrong, but I haven't been able to find a
There may be situations where I would need to find an object by parameters
This may be super easy to solve but I can't find the correct google
That may be really simple but I'm unable to find a good answer. How
I'm may be missing something but I can't find the Delphi 2007 WSDL Importer
May be I am getting old, but I can't find it...
Im trying to find records in a VARCHAR column that may contain a NUL
How do I find the number in line number may not be in the
This may be a very simple problem, but I couldn't find an answer googleing
I've searched but couldn't find any results (my terminology may be off) so forgive

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.