Пример #1
0
        private void Window_TextEntered(object sender, TextEventArgs e)
        {
            if (!IsSelected)
            {
                return;
            }

            // Don't handle input if the key press event did something
            if (blockTextInput)
            {
                blockTextInput = false;
                return;
            }

            string unicode = e.Unicode;

            if (unicode == "\b")
            {
                // Backspace, delete text
                if (Text.Length > 0)
                {
                    Text = Text.Substring(0, Text.Length - 1);
                }
            }
            else
            {
                // Append text
                Text = Text.Insert(cursor++, unicode);
            }
        }
Пример #2
0
        private void Window_KeyPressed(object sender, SFML.Window.KeyEventArgs e)
        {
            if (!IsSelected)
            {
                return;
            }

            if (e.Control)
            {
                if (e.Code == Keyboard.Key.C)
                {
                    Clipboard.SetText(Text);
                    blockTextInput = true;
                }
                else if (e.Code == Keyboard.Key.V)
                {
                    Text           = Text.Insert(cursor, Clipboard.GetText());
                    blockTextInput = true;
                }
            }
            else
            {
                if (e.Code == Keyboard.Key.Left)
                {
                    CursorPosition--;
                }
                else if (e.Code == Keyboard.Key.Right)
                {
                    CursorPosition++;
                }
                else if (e.Code == Keyboard.Key.Return)
                {
                    if (OnTextConfirmedHandler != null)
                    {
                        OnTextConfirmedHandler(this);
                    }
                    blockTextInput = true;
                }
            }
        }