locked
How to identify the Ctrl+Tab in PasswordBox in Windows Store App

    Question

  • Hi,

    i have to use the passwordbox  in Windows 8 store app.

    in passwordbox i need to restrict only numbers to be entered. i have tried doing that in keydown event.

    but the problem is with Ctrl+Tab, Tab, Shift+Tab, Shift+Number.

    I somehow tried to manage with Shift+Number, Shift+Tab. but not able to identify the Ctrl+Tab pressed and differentiate the Ctrl+Tab and Tab.

    Passwordbox has restriction that we cannot set the cursor position problematically. so Key_Up or Password_Changed event cannot be used. and it should be handled with keyDown vent.

    This is the Code i am using it to manage with the Shift+Tab, Shift+Number, Tab, Non-Digits.

      Shift+Tab--> Navigate to previous Control.

    Shift+Number --> special characters to be avoided.

    Tab--> Navigate to next Control

      private void txtPassword_KeyDown(object sender, KeyRoutedEventArgs e)
            {
                if (e.Key == VirtualKey.Shift)
                {
                    txtPassword.KeyUp += test_KeyUp;
                    shiftPressed = true;
                }
                if (shiftPressed)
                {
                    if (!(e.Key == VirtualKey.Tab))
                    e.Handled = true;
                }
                else
                {
                    string result = e.Key.ToString();
                    if (!result.Contains("Number") && !result.Contains("Tab"))
                    {
                        e.Handled = true;
                    }
                }
            }

            void test_KeyUp(object sender, KeyRoutedEventArgs e)
            {
                if (e.Key == VirtualKey.Shift)
                {
                    shiftPressed = false;
                }
                  txtPassword.KeyUp -= test_KeyUp;
            }


    Actually in default PasswordBox , when we press Ctrl+Tab, displays '●' which is really not required. and also need to restrict paste(Ctrl+V)

    Can anyone please tell me how to handle the Ctrl+Tab, not to display '●'  and  restrict paste(Ctrl+V) in Keydown event?




    • Edited by Shilpa_k Saturday, March 29, 2014 11:51 AM
    Saturday, March 29, 2014 10:53 AM

Answers

  • Hi,

    That's may be a bug and when I implement code below in may app:

    private void Grid_KeyDown(object sender, KeyRoutedEventArgs e)
    {
        if (e.Key == VirtualKey.Control) isCtrlKeyPressed = true;
        else if (isCtrlKeyPressed)
        {
            switch (e.Key)
            {
                case VirtualKey.P: DemoMovie.Play(); break;
                case VirtualKey.A: DemoMovie.Pause(); break;
                case VirtualKey.S: DemoMovie.Stop(); break;
            }
        }
    }

    I found when I press Control+A, only Virtual Key Control is fired, but Virtual Key A cannot fire. But when I press Control+P, both Virtual Key Control and P can fire.

    I recommend you can try some codes below, when I press Control+Tab simultaneously,that can detect the Control+Tab virtual key:

    private void Grid_KeyDown(object sender, KeyRoutedEventArgs e)
            {
              
                var ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control);
                var shift = Window.Current.CoreWindow.GetKeyState(VirtualKey.Tab);
                if (ctrl.HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down) &&
                    shift.HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down) 
                   )
                {
                    Debug.WriteLine("Ctrl+Tab");
                    
                }
    
    
                
               
            }
    
    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, April 2, 2014 2:24 AM

All replies

  • Hi,

    following code was from this thread
    private void onKeyDown(object sender, KeyRoutedEventArgs e)
    {
        if (e.Key == VirtualKey.Control) m_ControlPressed = true;
        else if (m_ControlPressed && e.Key == VirtualKey.Tab)
        {
            // do some stuff
        }
    }

    And refer to the link to get more information:

    http://msdn.microsoft.com/en-us/library/windows/apps/hh868246.aspx

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, March 31, 2014 3:40 AM
  • Hello, 

    thanks or the replay. 

    i have done in the same way before it was not working. again once again  have tried it. its of no use.

    this is the code i have done in Key_Down event,

     if (e.Key == VirtualKey.Control)
                    {

                        controlPressed = true;
                    }
                else if (controlPressed && e.Key == VirtualKey.Tab)
                {
                    e.Handled = true;
                }

    control is not going inside the conditional statement (controlPressed && e.Key == VirtualKey.Tab)

    actually while pressing Ctrl+Tab, only Virtual Key Control is fired. but not Tab. if i  try to put  e.Handled = true; inside conditional statement (e.Key == VirtualKey.Control)  also, passwordbox is taking the value "\t" 

    Could you please verify it once?

    Regards,

    Shilpa K

    Tuesday, April 1, 2014 4:36 AM
  • Hi,

    That's may be a bug and when I implement code below in may app:

    private void Grid_KeyDown(object sender, KeyRoutedEventArgs e)
    {
        if (e.Key == VirtualKey.Control) isCtrlKeyPressed = true;
        else if (isCtrlKeyPressed)
        {
            switch (e.Key)
            {
                case VirtualKey.P: DemoMovie.Play(); break;
                case VirtualKey.A: DemoMovie.Pause(); break;
                case VirtualKey.S: DemoMovie.Stop(); break;
            }
        }
    }

    I found when I press Control+A, only Virtual Key Control is fired, but Virtual Key A cannot fire. But when I press Control+P, both Virtual Key Control and P can fire.

    I recommend you can try some codes below, when I press Control+Tab simultaneously,that can detect the Control+Tab virtual key:

    private void Grid_KeyDown(object sender, KeyRoutedEventArgs e)
            {
              
                var ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control);
                var shift = Window.Current.CoreWindow.GetKeyState(VirtualKey.Tab);
                if (ctrl.HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down) &&
                    shift.HasFlag(Windows.UI.Core.CoreVirtualKeyStates.Down) 
                   )
                {
                    Debug.WriteLine("Ctrl+Tab");
                    
                }
    
    
                
               
            }
    
    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, April 2, 2014 2:24 AM