Пример #1
0
        public App()
        {
            terminalWindow = new TerminalWindow();
            processHandler = new ProcessHandler("cmd.exe");

            terminalWindow.OnReadLine += (string line) =>
            {
                Console.WriteLine("> " + line);
                processHandler.WriteLine(line);
            };

            processHandler.OnOutputDataReceived += (object sender, DataReceivedEventArgs e) =>
            {
                Console.WriteLine("< " + e.Data);
                terminalWindow.WriteLine(e.Data);
            };

            key1 = KeyInterop.KeyFromVirtualKey(Int32.Parse(ConfigurationManager.AppSettings["Key1"]));
            key2 = KeyInterop.KeyFromVirtualKey(Int32.Parse(ConfigurationManager.AppSettings["Key2"]));

            Win32Interop.KeyTriggered = OnKeyTriggered;
            Win32Interop.SetKeyhook();

            Exit += OnExit;
            processHandler.Run();
        }
Пример #2
0
        public MainWindow()
        {
            InitializeComponent();

            // Create TerminalWindow
            _terminalWindow = new TerminalWindow(SendCommand, KillProcess, TerminalWindowUIUpdate);
            _terminalWindow.Show();

            // Apply changes in terminal data to TerminalWindow
            _terminalData.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(
                (object o, System.Collections.Specialized.NotifyCollectionChangedEventArgs target) =>
            {
                string retStr = "";

                if (_terminalData.Count > 1)
                {
                    for (int i = 0; i < _terminalData.Count - 1; i++)
                    {
                        retStr += _terminalData[i];
                        retStr += Environment.NewLine;
                    }

                    retStr += _terminalData[_terminalData.Count - 1];
                }
                else if (_terminalData.Count == 1)
                {
                    retStr += _terminalData[0];
                }

                Dispatcher.Invoke(() =>
                {
                    _terminalWindow.TerminalData_TextBox.Text = retStr;
                    _terminalWindow.TerminalData_TextBox.ScrollToEnd();
                });
            });

            // Get TerminalWindow handle
            IntPtr hWnd = new WindowInteropHelper(_terminalWindow).Handle;

            // Hide window from alt tab menu
            Win32Interop.HideWindowFromAltTabMenu(hWnd);

            // Initialize CoreMeterUtility for TerminalWindow
            _coreMeterUtility = new CoreMeterUtility(hWnd);

            // Initially lock TerminalWindow
            _coreMeterUtility.Lock();

            // Load settings from json file
            _settings = JsonConvert.DeserializeObject <BackgroundTerminalSettings>(File.ReadAllText(_configPath));

            ApplySettingsToTerminalWindow();

            _key1 = KeyInterop.KeyFromVirtualKey(_settings.Key1);
            _key2 = KeyInterop.KeyFromVirtualKey(_settings.Key2);

            Process_TextBox.Text   = _settings.ProcessPath;
            Key1_Button.Content    = _key1.ToString();
            Key2_Button.Content    = _key2.ToString();
            FontSize_TextBox.Text  = _settings.FontSize.ToString();
            FontColor_TextBox.Text = _settings.FontColor.ToString();
            PosX_TextBox.Text      = _settings.PosX.ToString();
            PosY_TextBox.Text      = _settings.PosY.ToString();
            Width_TextBox.Text     = _settings.Width.ToString();
            Height_TextBox.Text    = _settings.Height.ToString();

            if (_settings.NewlineTriggers == null)
            {
                _settings.NewlineTriggers = new List <NewlineTrigger>();
            }

            NewlineTriggers = new ObservableCollection <NewlineTrigger>(_settings.NewlineTriggers);

            // Set KeyTriggered callback delegate
            Win32Interop.KeyTriggered = KeyTriggered;

            // Initialize Global Keyhook
            Win32Interop.SetKeyhook();

            // Begin terminal process
            RunTerminalProcessAsync();

            DataContext = this;
        }