示例#1
0
        /// <summary>
        /// Called when [edit element loaded].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        protected override void OnEditElementLoaded(object sender, RoutedEventArgs e)
        {
            var dateTimeEdit = ((DateTimeEdit)sender);

            dateTimeEdit.TextChanged        += OnTextChanged;
            dateTimeEdit.WatermarkVisibility = Visibility.Collapsed;
            dateTimeEdit.Focus();
            if ((this.DataGrid.EditorSelectionBehavior == EditorSelectionBehavior.SelectAll || this.DataGrid.IsAddNewIndex(this.CurrentCellIndex.RowIndex)) && PreviewInputText == null)
            {
                dateTimeEdit.SelectAll();
                return;
            }
            else
            {
                if (PreviewInputText == null)
                {
                    var index = dateTimeEdit.Text.Length;
                    dateTimeEdit.Select(index + 1, 0);
                    return;
                }
                if (dateTimeEdit.CanEdit)
                {
                    ((DateTimeEdit)CurrentCellRendererElement).SelectedText = PreviewInputText.ToString();
                }
                TextCompositionManager.StartComposition(new TextComposition(InputManager.Current, (DateTimeEdit)CurrentCellRendererElement, PreviewInputText.ToString()));
            }
            PreviewInputText = null;
        }
示例#2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var psi = new ProcessStartInfo(System.Windows.Forms.Application.ExecutablePath);
            // launch the process through white application
            _application = TestStack.White.Application.Attach(Process.GetCurrentProcess());
            _mainWindow = _application.GetWindow("MainWindow", InitializeOption.NoCache);

            Point textboxLocation = txtbox.PointToScreen(new Point(0d, 0d));

            Microsoft.Test.Input.Mouse.MoveTo(new System.Drawing.Point((int)textboxLocation.X, (int)textboxLocation.Y));
            Microsoft.Test.Input.Mouse.Click(Microsoft.Test.Input.MouseButton.Left);

            TextCompositionManager.StartComposition(
                new TextComposition(InputManager.Current, txtbox, "pwpito"));

            //var button = _mainWindow.Get<Button>("stopButton");
            //button.Click();


            //TextCompositionManager.StartComposition(
            //    new TextComposition(InputManager.Current, txtbox, " papito"));

            //AutomationElement automationElement = _mainWindow.GetElement(SearchCriteria.ByAutomationId("stopButton"));
            //var invokePattern = automationElement.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
            //invokePattern.Invoke();

            //this.stopButton.

            //Keyboard.Type("Hello world.");
            //Keyboard.Press(Key.Shift);
            //Keyboard.Type("hello, capitalized world.");
            //Thread.Sleep(100);
            //SendKeys.SendWait("pepe");
            // Keyboard.Release(Key.Shift);
        }
示例#3
0
    private static void TextBox_ConvertHandler(object sender, KeyEventArgs e)
    {
        var textBox = sender as TextBox;

        if (e.Key == Key.Oem4)      // "["
        {
            string convertString = "\\u0001";
            TextCompositionManager.StartComposition(new TextComposition(InputManager.Current, textBox, convertString));
            e.Handled = true;
        }
    }
示例#4
0
        private void SelectCharactorButtonOnClick(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;
            var text   = button.Content as string;

            if (text != null)
            {
                var composition = new TextComposition(InputManager.Current, this.Output, text);
                TextCompositionManager.StartComposition(composition);
                this.Clear();
            }
        }
示例#5
0
        private void OnTextBoxKeyDown(object sender, KeyEventArgs eventArgs)
        {
            // Translate the numpad decimal key to the correct decimal separator.
            if (eventArgs.Key == Key.Decimal)
            {
                eventArgs.Handled = true;

                var cultureInfo     = _textBox.Language.GetSpecificCulture();
                var textComposition = new TextComposition(InputManager.Current, _textBox, cultureInfo.NumberFormat.NumberDecimalSeparator);
                TextCompositionManager.StartComposition(textComposition);
            }
        }
示例#6
0
        //--------------------------------------------------------------------------------------------------

        #endregion

        #region Keyboard Input

        static bool _SendKeyEvent(int key, bool isUp)
        {
            bool success = false;
            int  vkey    = key & 0xff;

            Application.Current.Dispatcher.Invoke(() =>
            {
                var sourceElement = Keyboard.PrimaryDevice.ActiveSource;
                var focusElement  = Keyboard.PrimaryDevice.FocusedElement;
                if (focusElement == null || sourceElement == null)
                {
                    return;
                }

                var tunnelArgs         = new KeyEventArgs(Keyboard.PrimaryDevice, sourceElement, 0, KeyInterop.KeyFromVirtualKey(vkey));
                tunnelArgs.RoutedEvent = isUp ? Keyboard.PreviewKeyUpEvent : Keyboard.PreviewKeyDownEvent;
                focusElement.RaiseEvent(tunnelArgs);

                if (!tunnelArgs.Handled)
                {
                    var bubbleArgs         = new KeyEventArgs(Keyboard.PrimaryDevice, sourceElement, 0, KeyInterop.KeyFromVirtualKey(vkey));
                    bubbleArgs.RoutedEvent = isUp ? Keyboard.KeyUpEvent : Keyboard.KeyDownEvent;
                    focusElement.RaiseEvent(bubbleArgs);

                    if (!bubbleArgs.Handled && !isUp)
                    {
                        var sb           = new StringBuilder();
                        byte[] bKeyState = new byte[255];
                        if ((key & 0x0100) > 0)
                        {
                            bKeyState[0x10] = 0x80;
                        }
                        if ((key & 0x0200) > 0)
                        {
                            bKeyState[0x11] = 0x80;
                        }
                        if ((key & 0x0400) > 0)
                        {
                            bKeyState[0x12] = 0x80;
                        }
                        uint lScanCode = Win32Api.MapVirtualKey((uint)(vkey), Win32Api.MapVirtualKeyMapTypes.MAPVK_VK_TO_VSC);
                        Win32Api.ToUnicode((uint)(vkey), lScanCode, bKeyState, sb, 5, 0);

                        TextCompositionManager.StartComposition(new TextComposition(InputManager.Current, Keyboard.FocusedElement, sb.ToString()));
                    }
                }

                success = true;
            });
            return(success);
        }
示例#7
0
        public static void WriteText(this TextBox textBox, string text, bool overwrite = true)
        {
            if (overwrite)
            {
                textBox.SelectAll();
            }
            var composition = new TextComposition(InputManager.Current, textBox, text);

            TextCompositionManager.StartComposition(composition);
            if (text == "")
            {
                textBox.Text = "";
            }
        }
示例#8
0
        private void keyClick(object sender, RoutedEventArgs e)
        {
            Button button = (Button)sender;

            if (button.Equals(btnA))
            {
                keyPressed = 'a';
            }
            else if (button.Equals(btnB))
            {
                keyPressed = 'b';
            }
            else if (button.Equals(btnC))
            {
                keyPressed = 'c';
            }
            else if (button.Equals(btnD))
            {
                keyPressed = 'd';
            }
            else if (button.Equals(btnE))
            {
                keyPressed = 'e';
            }
            else if (button.Equals(btnF))
            {
                keyPressed = 'f';
            }
            else if (button.Equals(btnG))
            {
                keyPressed = 'g';
            }
            else if (button.Equals(btnH))
            {
                keyPressed = 'h';
            }
            else if (button.Equals(btnI))
            {
                keyPressed = 'i';
            }
            else if (button.Equals(btnJ))
            {
                keyPressed = 'j';
            }
            else if (button.Equals(btnK))
            {
                keyPressed = 'k';
            }
            else if (button.Equals(btnL))
            {
                keyPressed = 'l';
            }
            else if (button.Equals(btnM))
            {
                keyPressed = 'm';
            }
            else if (button.Equals(btnN))
            {
                keyPressed = 'n';
            }
            else if (button.Equals(btnO))
            {
                keyPressed = 'o';
            }
            else if (button.Equals(btnP))
            {
                keyPressed = 'p';
            }
            else if (button.Equals(btnQ))
            {
                keyPressed = 'q';
            }
            else if (button.Equals(btnR))
            {
                keyPressed = 'r';
            }
            else if (button.Equals(btnS))
            {
                keyPressed = 's';
            }
            else if (button.Equals(btnT))
            {
                keyPressed = 't';
            }
            else if (button.Equals(btnU))
            {
                keyPressed = 'u';
            }
            else if (button.Equals(btnV))
            {
                keyPressed = 'v';
            }
            else if (button.Equals(btnW))
            {
                keyPressed = 'w';
            }
            else if (button.Equals(btnX))
            {
                keyPressed = 'x';
            }
            else if (button.Equals(btnY))
            {
                keyPressed = 'y';
            }
            else if (button.Equals(btnZ))
            {
                keyPressed = 'z';
            }
            else if (button.Equals(btnBackspace))
            {
                keyPressed = '\b';
            }

            if (textBoxUsername.IsFocused)
            {
                int usernameCaretIndex = textBoxUsername.CaretIndex;

                if (keyPressed == '\b' && textBoxUsername.Text.Length > 0)
                {
                    textBoxUsername.Text       = textBoxUsername.Text.Remove(usernameCaretIndex - 1, 1);
                    textBoxUsername.CaretIndex = usernameCaretIndex - 1;
                }
                else
                {
                    textBoxUsername.Text       = textBoxUsername.Text.Insert(usernameCaretIndex, keyPressed.ToString());
                    textBoxUsername.CaretIndex = usernameCaretIndex + 1;
                }
            }
            else if (passwordBox.IsFocused)
            {
                //	Due to security reason, caret index of passwordbox is not retrievable

                if (keyPressed == '\b' && passwordBox.Password.Length > 0)
                {
                    //	Remove all password
                    passwordBox.Password = "";
                }
                else
                {
                    //	Use TextCompositionManager to input at current caret
                    TextCompositionManager.StartComposition(new TextComposition(InputManager.Current, passwordBox, keyPressed.ToString()));
                }
            }
        }
示例#9
0
        //	Execute press functions
        private void HandPointerPressReleaseEvent(object sender, HandPointerEventArgs e)
        {
            if (capturedHandPointer == e.HandPointer)
            {
                if (e.HandPointer.GetIsOver(btnCancelLogin))
                {
                    Close();
                    VisualStateManager.GoToState(btnCancelLogin, "MouseOver", true);
                }
                else if (e.HandPointer.GetIsOver(btnLogin))
                {
                    //	Setup custom message box
                    CustomMessageBox customMessageBox = new CustomMessageBox(kinectSensorChooser);

                    //	Check if username entered is at least 3 characters long
                    if (textBoxUsername.Text.Length < 3)
                    {
                        //	Show error message dialog
                        customMessageBox.ShowText("Username is at least 3 characters long!");
                    }
                    //	Check password length is at least 3 characters long
                    else if (passwordBox.Password.Length < 3)
                    {
                        //	Show error message dialog
                        customMessageBox.ShowText("Password is at least 3 characters long!");
                    }
                    else
                    {
                        //	Create the player repository object
                        PlayersRepository pro = new PlayersRepository();

                        //	Hash the password
                        SHA256 sha256 = SHA256.Create();
                        byte[] bytes  = Encoding.UTF8.GetBytes(passwordBox.Password);
                        byte[] hash   = sha256.ComputeHash(bytes);

                        StringBuilder result = new StringBuilder();
                        for (int i = 0; i < hash.Length; i++)
                        {
                            result.Append(hash[i].ToString("X2"));
                        }

                        //	Search database for this username
                        List <PlayersRepository.PlayerDto> player = pro.GetPlayerWithUsername(textBoxUsername.Text);

                        //	If player exist
                        if (player.Count == 1)
                        {
                            //	If password match then log them in
                            if (result.ToString().Contains(player[0].Password))
                            {
                                //	Retrieve and save the player ID
                                playerID = player[0].Id;

                                //	Show dialog that the login is successful
                                customMessageBox.ShowText("Successfully logged in");

                                //	Close after succesfully logged in
                                Close();
                            }
                            else
                            {
                                //	Show dialog that the login is not successful
                                customMessageBox.ShowText("Password is incorrect!");

                                //	Clear the incorrect password
                                passwordBox.Password = "";
                            }
                        }
                        else
                        {
                            //	Show dialog that the login is not successful
                            customMessageBox.ShowText("Player doesn't exist!");
                        }
                    }

                    VisualStateManager.GoToState(btnLogin, "MouseOver", true);
                }
                else if (e.HandPointer.GetIsOver(textBoxUsername))
                {
                    textBoxUsername.Focus();
                    VisualStateManager.GoToState(textBoxUsername, "MouseOver", true);
                }
                else if (e.HandPointer.GetIsOver(passwordBox))
                {
                    passwordBox.Focus();
                    VisualStateManager.GoToState(passwordBox, "MouseOver", true);
                }
                else
                {
                    try
                    {
                        if (e.HandPointer.GetIsOver((Button)sender))
                        {
                            Button button = null;
                            try
                            {
                                button = (Button)sender;
                            }
                            catch (Exception)
                            {
                            }

                            if (button.Equals(btnA))
                            {
                                keyPressed = 'a';
                            }
                            else if (button.Equals(btnB))
                            {
                                keyPressed = 'b';
                            }
                            else if (button.Equals(btnC))
                            {
                                keyPressed = 'c';
                            }
                            else if (button.Equals(btnD))
                            {
                                keyPressed = 'd';
                            }
                            else if (button.Equals(btnE))
                            {
                                keyPressed = 'e';
                            }
                            else if (button.Equals(btnF))
                            {
                                keyPressed = 'f';
                            }
                            else if (button.Equals(btnG))
                            {
                                keyPressed = 'g';
                            }
                            else if (button.Equals(btnH))
                            {
                                keyPressed = 'h';
                            }
                            else if (button.Equals(btnI))
                            {
                                keyPressed = 'i';
                            }
                            else if (button.Equals(btnJ))
                            {
                                keyPressed = 'j';
                            }
                            else if (button.Equals(btnK))
                            {
                                keyPressed = 'k';
                            }
                            else if (button.Equals(btnL))
                            {
                                keyPressed = 'l';
                            }
                            else if (button.Equals(btnM))
                            {
                                keyPressed = 'm';
                            }
                            else if (button.Equals(btnN))
                            {
                                keyPressed = 'n';
                            }
                            else if (button.Equals(btnO))
                            {
                                keyPressed = 'o';
                            }
                            else if (button.Equals(btnP))
                            {
                                keyPressed = 'p';
                            }
                            else if (button.Equals(btnQ))
                            {
                                keyPressed = 'q';
                            }
                            else if (button.Equals(btnR))
                            {
                                keyPressed = 'r';
                            }
                            else if (button.Equals(btnS))
                            {
                                keyPressed = 's';
                            }
                            else if (button.Equals(btnT))
                            {
                                keyPressed = 't';
                            }
                            else if (button.Equals(btnU))
                            {
                                keyPressed = 'u';
                            }
                            else if (button.Equals(btnV))
                            {
                                keyPressed = 'v';
                            }
                            else if (button.Equals(btnW))
                            {
                                keyPressed = 'w';
                            }
                            else if (button.Equals(btnX))
                            {
                                keyPressed = 'x';
                            }
                            else if (button.Equals(btnY))
                            {
                                keyPressed = 'y';
                            }
                            else if (button.Equals(btnZ))
                            {
                                keyPressed = 'z';
                            }
                            else if (button.Equals(btnBackspace))
                            {
                                keyPressed = '\b';
                            }

                            if (textBoxUsername.IsFocused)
                            {
                                int usernameCaretIndex = textBoxUsername.CaretIndex;

                                if (keyPressed == '\b' && textBoxUsername.Text.Length > 0)
                                {
                                    textBoxUsername.Text       = textBoxUsername.Text.Remove(usernameCaretIndex - 1, 1);
                                    textBoxUsername.CaretIndex = usernameCaretIndex - 1;
                                }
                                else
                                {
                                    textBoxUsername.Text       = textBoxUsername.Text.Insert(usernameCaretIndex, keyPressed.ToString());
                                    textBoxUsername.CaretIndex = usernameCaretIndex + 1;
                                }
                            }
                            else if (passwordBox.IsFocused)
                            {
                                //	Due to security reason, caret index of passwordbox is not retrievable

                                if (keyPressed == '\b' && passwordBox.Password.Length > 0)
                                {
                                    //	Remove all password
                                    passwordBox.Password = "";
                                }
                                else
                                {
                                    //	Use TextCompositionManager to input at current caret
                                    TextCompositionManager.StartComposition(new TextComposition(InputManager.Current, passwordBox, keyPressed.ToString()));
                                }
                            }
                        }
                        else
                        {
                            VisualStateManager.GoToState(btnCancelLogin, "Normal", true);
                            VisualStateManager.GoToState(btnLogin, "Normal", true);
                            VisualStateManager.GoToState(textBoxUsername, "Normal", true);
                            VisualStateManager.GoToState(passwordBox, "Normal", true);
                            VisualStateManager.GoToState(btnA, "Normal", true);
                            VisualStateManager.GoToState(btnB, "Normal", true);
                            VisualStateManager.GoToState(btnC, "Normal", true);
                            VisualStateManager.GoToState(btnD, "Normal", true);
                            VisualStateManager.GoToState(btnE, "Normal", true);
                            VisualStateManager.GoToState(btnF, "Normal", true);
                            VisualStateManager.GoToState(btnH, "Normal", true);
                            VisualStateManager.GoToState(btnI, "Normal", true);
                            VisualStateManager.GoToState(btnJ, "Normal", true);
                            VisualStateManager.GoToState(btnK, "Normal", true);
                            VisualStateManager.GoToState(btnL, "Normal", true);
                            VisualStateManager.GoToState(btnM, "Normal", true);
                            VisualStateManager.GoToState(btnN, "Normal", true);
                            VisualStateManager.GoToState(btnO, "Normal", true);
                            VisualStateManager.GoToState(btnP, "Normal", true);
                            VisualStateManager.GoToState(btnQ, "Normal", true);
                            VisualStateManager.GoToState(btnR, "Normal", true);
                            VisualStateManager.GoToState(btnS, "Normal", true);
                            VisualStateManager.GoToState(btnT, "Normal", true);
                            VisualStateManager.GoToState(btnU, "Normal", true);
                            VisualStateManager.GoToState(btnV, "Normal", true);
                            VisualStateManager.GoToState(btnW, "Normal", true);
                            VisualStateManager.GoToState(btnX, "Normal", true);
                            VisualStateManager.GoToState(btnY, "Normal", true);
                            VisualStateManager.GoToState(btnZ, "Normal", true);
                            VisualStateManager.GoToState(btnBackspace, "Normal", true);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }

                e.HandPointer.Capture(null);
                e.Handled = true;
            }
        }