コード例 #1
0
        private void ReadKeys()
        {
            Keys[] PressedKeys = KeyboardHelper.KeyPressed();

            foreach (Keys ActiveKey in PressedKeys)
            {
                if (!LastPressedKeys.Contains(ActiveKey))
                {
                    switch (ActiveKey)
                    {
                    case Keys.LeftShift:
                    case Keys.RightShift:
                    case Keys.LeftControl:
                    case Keys.RightControl:
                    case Keys.LeftAlt:
                    case Keys.RightAlt:
                    case Keys.PrintScreen:
                    case Keys.Up:
                    case Keys.Down:
                    case Keys.Escape:
                        break;

                    case Keys.OemComma:
                        Text       += "'";
                        TextVisible = Text;
                        MessageCursorIndex++;
                        UpdateMessengerCursor();
                        break;

                    case Keys.Enter:
                        OnConfirm(Text);
                        break;

                    case Keys.Right:
                        if (MessageCursorIndex < Text.Length)
                        {
                            MessageCursorIndex++;
                            UpdateMessengerCursor();
                        }
                        break;

                    case Keys.Left:
                        if (MessageCursorIndex > 0)
                        {
                            MessageCursorIndex--;
                            UpdateMessengerCursor();
                        }
                        break;

                    case Keys.Space:
                        Text       += " ";
                        TextVisible = Text;
                        MessageCursorIndex++;
                        UpdateMessengerCursor();
                        break;

                    case Keys.Back:
                        if (MessageCursorIndex > 0)
                        {
                            Text = Text.Remove(--MessageCursorIndex, 1);
                            UpdateMessengerCursor();
                        }
                        break;

                    case Keys.Delete:
                        if (MessageCursorIndex < Text.Length)
                        {
                            Text = Text.Remove(MessageCursorIndex, 1);
                            UpdateMessengerCursor();
                        }
                        break;

                    case Keys.D0:
                    case Keys.D1:
                    case Keys.D2:
                    case Keys.D3:
                    case Keys.D4:
                    case Keys.D5:
                    case Keys.D6:
                    case Keys.D7:
                    case Keys.D8:
                    case Keys.D9:
                    case Keys.NumPad0:
                    case Keys.NumPad1:
                    case Keys.NumPad2:
                    case Keys.NumPad3:
                    case Keys.NumPad4:
                    case Keys.NumPad5:
                    case Keys.NumPad6:
                    case Keys.NumPad7:
                    case Keys.NumPad8:
                    case Keys.NumPad9:
                        Text       += ActiveKey.ToString().Replace("D", "").Replace("NumPad", "");
                        TextVisible = Text;
                        MessageCursorIndex++;
                        UpdateMessengerCursor();
                        break;

                    default:
                        if (DigitsOnly)
                        {
                            break;
                        }

                        if (KeyboardHelper.KeyHold(Keys.LeftShift) || KeyboardHelper.KeyHold(Keys.RightShift))
                        {
                            Text += ActiveKey.ToString();
                        }
                        else
                        {
                            Text += ActiveKey.ToString().ToLower();
                        }
                        TextVisible = Text;
                        MessageCursorIndex++;
                        UpdateMessengerCursor();
                        break;
                    }
                }
            }

            LastPressedKeys = PressedKeys;
        }
コード例 #2
0
        private void ReadKeys()
        {
            Keys[] PressedKeys = KeyboardHelper.KeyPressed();

            foreach (Keys ActiveKey in PressedKeys)
            {
                if (!LastPressedKeys.Contains(ActiveKey))
                {
                    switch (ActiveKey)
                    {
                    case Keys.LeftShift:
                    case Keys.RightShift:
                    case Keys.LeftControl:
                    case Keys.RightControl:
                    case Keys.LeftAlt:
                    case Keys.RightAlt:
                    case Keys.PrintScreen:
                    case Keys.Up:
                    case Keys.Down:
                    case Keys.Escape:
                        break;

                    case Keys.OemComma:
                        AddText("'");
                        break;

                    case Keys.Enter:
                        if (!string.IsNullOrEmpty(Text))
                        {
                            OnConfirm(Text);
                        }
                        break;

                    case Keys.Right:
                        if (MessageCursorIndex < Text.Length)
                        {
                            MessageCursorIndex++;
                            UpdateMessengerCursor();
                        }
                        break;

                    case Keys.Left:
                        if (MessageCursorIndex > 0)
                        {
                            MessageCursorIndex--;
                            UpdateMessengerCursor();
                        }
                        break;

                    case Keys.Space:
                        AddText(" ");
                        break;

                    case Keys.Back:
                        if (MessageSelectionCursorIndex != MessageCursorIndex)
                        {
                            DeleteSelection();
                        }
                        else
                        {
                            if (MessageCursorIndex > 0)
                            {
                                Text = Text.Remove(--MessageCursorIndex, 1);
                            }
                        }
                        UpdateMessengerCursor();
                        break;

                    case Keys.Delete:
                        if (MessageSelectionCursorIndex != MessageCursorIndex)
                        {
                            DeleteSelection();
                        }
                        else
                        {
                            if (MessageCursorIndex < Text.Length)
                            {
                                Text = Text.Remove(MessageCursorIndex, 1);
                            }
                        }
                        UpdateMessengerCursor();
                        break;

                    case Keys.D0:
                    case Keys.D1:
                    case Keys.D2:
                    case Keys.D3:
                    case Keys.D4:
                    case Keys.D5:
                    case Keys.D6:
                    case Keys.D7:
                    case Keys.D8:
                    case Keys.D9:
                    case Keys.NumPad0:
                    case Keys.NumPad1:
                    case Keys.NumPad2:
                    case Keys.NumPad3:
                    case Keys.NumPad4:
                    case Keys.NumPad5:
                    case Keys.NumPad6:
                    case Keys.NumPad7:
                    case Keys.NumPad8:
                    case Keys.NumPad9:
                        AddText(ActiveKey.ToString().Replace("D", "").Replace("NumPad", ""));
                        break;

                    case Keys.Divide:
                        AddText("/");
                        break;

                    default:
                        if (DigitsOnly)
                        {
                            break;
                        }

                        if (KeyboardHelper.KeyHold(Keys.LeftShift) || KeyboardHelper.KeyHold(Keys.RightShift))
                        {
                            AddText(ActiveKey.ToString());
                        }
                        else
                        {
                            AddText(ActiveKey.ToString().ToLower());
                        }
                        break;
                    }
                }
            }

            if (PressedKeys.Length > 0)
            {
                IsCursorVisible = true;
                BlinkingTimer   = 0d;
            }

            LastPressedKeys = PressedKeys;
        }