Пример #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
        private void MainWindow_Closed(object sender, EventArgs e)
        {
            // End global keyhook
            Win32Interop.DestroyKeyhook();

            // Close terminal window
            _terminalWindow.Close();

            Environment.Exit(0);
        }
Пример #3
0
        private void OnKeyTriggered(int keyCode)
        {
            int vKey1 = KeyInterop.VirtualKeyFromKey((Key)key1);
            int vKey2 = KeyInterop.VirtualKeyFromKey((Key)key2);

            if (keyCode == vKey2 && Win32Interop.IsKeyDown(vKey1))
            {
                Win32Interop.ClickSimulateFocus(terminalWindow);
                Win32Interop.SetForegroundWindow(terminalWindow.Handle);
                Win32Interop.SetActiveWindow(terminalWindow.Handle);
                terminalWindow.Focus();
                terminalWindow.Activate();
            }
        }
Пример #4
0
        private void KeyTriggered(int keyCode)
        {
            if (_key1 != null && _key2 != null)
            {
                int vKey1 = KeyInterop.VirtualKeyFromKey((Key)_key1);
                int vKey2 = KeyInterop.VirtualKeyFromKey((Key)_key2);

                if (keyCode == vKey2 && Win32Interop.IsKeyDown(vKey1))
                {
                    _terminalWindow.Input_TextBox.Text = "";

                    if (!_terminalWindowActive)
                    {
                        Win32Interop.ClickSimulateFocus(_terminalWindow);
                        Win32Interop.SetForegroundWindow((new WindowInteropHelper(_terminalWindow)).Handle);
                        Win32Interop.SetActiveWindow((new WindowInteropHelper(_terminalWindow)).Handle);
                        FocusManager.SetFocusedElement(_terminalWindow, _terminalWindow.Input_TextBox);
                        Keyboard.Focus(_terminalWindow.Input_TextBox);

                        _terminalWindowActive = true;
                    }
                    else
                    {
                        _terminalWindowActive = false;

                        Keyboard.ClearFocus();
                    }
                }
            }

            if (_awaitingKey1)
            {
                _key1 = KeyInterop.KeyFromVirtualKey(keyCode);

                _awaitingKey1 = false;

                Key1_Button.Content = _key1.ToString();
            }

            if (_awaitingKey2)
            {
                _key2 = KeyInterop.KeyFromVirtualKey(keyCode);

                _awaitingKey2 = false;

                Key2_Button.Content = _key2.ToString();
            }
        }
Пример #5
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;
        }
Пример #6
0
 private void OnExit(object sender, EventArgs e)
 {
     Win32Interop.DestroyKeyhook();
     terminalWindow.Close();
     Environment.Exit(0);
 }