AcornPublishing_wpf/9780735619579-master/AppsCodeMarkup/Chapter 03/RecordKeystrokes/RecordKeystrokes.cs
//-------------------------------------------------
// RecordKeystrokes.cs (c) 2006 by Charles Petzold
//-------------------------------------------------
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;

namespace Petzold.RecordKeystrokes
{
    public class RecordKeystrokes : Window
    {
        [STAThread]
        public static void Main()
        {
            Application app = new Application();
            app.Run(new RecordKeystrokes());
        }
        public RecordKeystrokes()
        {
            Title = "Record Keystrokes";
            Content = "";
        }
        protected override void OnTextInput(TextCompositionEventArgs args)
        {
            base.OnTextInput(args);
            string str = Content as string;

            if (args.Text == "\b")
            {
                if (str.Length > 0)
                    str = str.Substring(0, str.Length - 1);
            }
            else
            {
                str += args.Text;
            }
            Content = str;
        }
    }
}