public InputDeviceHelper(DependencyObject context) { if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) { throw new InvalidOperationException("The calling thread must be STA!"); } Dispatcher = Dispatcher.CurrentDispatcher; var keys = Enum.GetValues(typeof(Key)).Cast <Key>().ToArray(); _kbState = new Dictionary <Key, bool>(keys.Length); foreach (var key in keys) { _kbState[key] = false; } var mouseButtons = Enum.GetValues(typeof(MouseButton)).Cast <MouseButton>().ToArray(); _mbState = new Dictionary <MouseButton, bool>(mouseButtons.Length); foreach (var button in mouseButtons) { _mbState[button] = false; } Keyboard.AddKeyUpHandler(context, OnKeyStateChanged); Keyboard.AddKeyDownHandler(context, OnKeyStateChanged); Keyboard.AddLostKeyboardFocusHandler(context, OnKeyboardFocusChanged); Mouse.AddMouseUpHandler(context, OnMouseButtonStateChanged); Mouse.AddMouseDownHandler(context, OnMouseButtonStateChanged); }
public void Bind() { if (this.HasBinded) { this.Unbind(); } this.HasBinded = true; DependencyObject bindedELement = this.BindedElement; if (bindedELement != null) { Keyboard.AddGotKeyboardFocusHandler(bindedELement, this._keyboardFocusChanged); Keyboard.AddLostKeyboardFocusHandler(bindedELement, this._keyboardFocusChanged); if (this._hiddenElements != null && !this.BindingToRoot) { foreach (var hiddenElement in this._hiddenElements) { Keyboard.AddGotKeyboardFocusHandler(hiddenElement, this._keyboardFocusChanged); Keyboard.AddLostKeyboardFocusHandler(hiddenElement, this._keyboardFocusChanged); } } this.UpdateFocusElement(Keyboard.FocusedElement, true); } }
public ViewPage() { InitializeComponent(); DataContext = this; if (!string.IsNullOrEmpty(App.Command)) { mCurrentPage = new HistoryItem(App.Command); } else { mCurrentPage = new HistoryItem(PagesDal.DEFAULT_PAGE); } Keyboard.AddGotKeyboardFocusHandler(this, gotKeyboardFocus); Keyboard.AddLostKeyboardFocusHandler(this, lostKeyboardFocus); webBrowser1.Navigating += webBrowser1_Navigating; webBrowser1.LoadCompleted += webBrowser1_LoadCompleted; var jsinterop = new JavascriptInterop(); webBrowser1.ObjectForScripting = jsinterop; jsinterop.InvokeFromJavascript += jsinterop_InvokeFromJavascript; webBrowser1.PreviewKeyDown += webBrowser1_KeyDown; mSearchWatermarkText = textBoxSearch.Text; mSearchWatermarkBrush = textBoxSearch.Foreground; mSearchWatermarkFontStyle = textBoxSearch.FontStyle; mDal = new PagesDal(); EditCommand = new RelayCommand(() => buttonEdit_Click(null, null)); InputBindings.Add(new KeyBinding(EditCommand, new KeyGesture(Key.E, ModifierKeys.Control))); BackCommand = new RelayCommand(() => buttonBack_Click(null, null)); HomeCommand = new RelayCommand(() => buttonHome_Click(null, null)); InputBindings.Add(new KeyBinding(HomeCommand, new KeyGesture(Key.Home, ModifierKeys.Alt))); FindCommand = new RelayCommand(() => textBoxSearch.Focus()); InputBindings.Add(new KeyBinding(FindCommand, new KeyGesture(Key.OemQuestion, ModifierKeys.Control))); RecentCommand = new RelayCommand(() => recentModifications()); InputBindings.Add(new KeyBinding(RecentCommand, new KeyGesture(Key.R, ModifierKeys.Control))); initWatcher(); refresh(); restorePosition(); Loaded += (sender, e) => registerHotkey(); Unloaded += (sender, e) => unregisterHotkey(); }