locked
CapsLock And NumLock on and off RRS feed

  • Question

  • Hello. I have a problem, i want to build a little function that tells if the CapsLock or NumLock is on or off, have done some code but nothing happens so somewhere we have an error.

     public LoginWindow()
            {
                InitializeComponent();
                
                bool capslock, numlock;
    
                capslock = Console.CapsLock;
                numlock = Console.NumberLock;
    
                if (capslock == true)
                {
                    ErrorBox.Visibility = Visibility.Visible;
                    ErrorBoxFade_BeginStoryboard.Storyboard.Begin();
                    connectionstatus.Content = "Caps Lock is On, ya";
                }
                else
                {
                    ErrorBox.Visibility = Visibility.Visible;
                    ErrorBoxFade_BeginStoryboard.Storyboard.Stop();
                }
    
                if (numlock == true)
                {
                    ErrorBox.Visibility = Visibility.Visible;
                    ErrorBoxFade_BeginStoryboard.Storyboard.Begin();
                    connectionstatus.Content = "Num Lock is On, ya";
                }
                else
                {
                    ErrorBox.Visibility = Visibility.Visible;
                    ErrorBoxFade_BeginStoryboard.Storyboard.Stop();
                }
            }

    Thursday, July 16, 2009 7:55 PM

All replies

  • Typically, you pass a reference for a FrameworkElement into the Begin method.

    Try:

    ErrorBoxFade_BeginStoryboard.Storyboard.Begin(ErrorBox, true);


    David Morton - http://blog.davemorton.net/ - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client
    Thursday, July 16, 2009 8:11 PM
  • I will test it but the code on other places that just looks like

    ErrorBoxFade_BeginStoryboard.Storyboard.Begin();

    and it works fine.

    Thursday, July 16, 2009 8:16 PM
  • You have that code in other places?  It is possible, you know to have conflicting calls to Begin() and Stop().  If your caps lock is on, but your number lock isn't, then you'll call Begin() followed immediately by Stop(), and to your eyes, nothing would happen.

    Try:

    if (capslock || numlock)
    {
       // begin
    } else {
       // stop
    }
    David Morton - http://blog.davemorton.net/ - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client
    Thursday, July 16, 2009 8:19 PM
  • Nothing happens whit your code example..
    Thursday, July 16, 2009 8:55 PM
  • capslock = Console.CapsLock ;
    numlock = Console.NumberLock ;
    Are these two correct?

    Regards,
    Kristaps.

    P.S.: Epic shoop is epic.
    Thursday, July 16, 2009 10:04 PM
  • It should be i think.
    Friday, July 17, 2009 1:36 PM
  • When the program starts and numlock or capslock is on before the program starts the program is aware of that they are on or of. But not if i turn them on and off when the program is done loading.
    Wednesday, July 22, 2009 4:58 PM