public BasicSettingsData(System.Windows.Controls.TextBox processTextfield) { var helper = new WindowInteropHelper(Application.Current.MainWindow); helper.EnsureHandle(); //get a handle witthout the need to show the window hotkeyListener = new Hotkey.HotkeyListener(helper.Handle); hotkeyListener?.RegisterHotKey(HotkeyMod1._Value | HotkeyMod2._Value, HotkeyKey._Value); this.bot = new Bot.Bot(new Input.Keyboard.User32_SendInput_VirtualKeycode()); hotkeyListener.OnHotKeyPressed += () => { if (this.IsBotRunning) { bot.Stop(); } else { bot.Start("\r" + this.HotkeyAction + "\r"); } this.IsBotRunning = !this.IsBotRunning; }; Application.Current.Dispatcher.ShutdownStarted += Dispatcher_ShutdownStarted; procChecker = new Timer(checkProcess, null, -1, -1); // init timer, but don`t start processTextfield.IsVisibleChanged += DependentUIElement_IsVisibleChanged; processTextfield.KeyUp += (a, b) => { procChecker.Change(TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(1)); }; }
protected virtual void NotifyPropertyChanged([CallerMemberName] String propertyName = "") { if (propertyName.Contains("Hotkey")) { hotkeyListener?.RegisterHotKey(HotkeyMod1._Value | HotkeyMod2._Value, HotkeyKey._Value); } PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); }