// ----------------------------------------------------------------------- // // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex.Input { using System; using System.Linq; using System.Reactive.Linq; using Perspex.Controls; using Perspex.Input.Raw; using Splat; public abstract class KeyboardDevice : IKeyboardDevice { public KeyboardDevice() { this.InputManager.RawEventReceived .OfType() .Where(x => x.Device == this) .Subscribe(this.ProcessRawEvent); } public IInputManager InputManager { get { return Locator.Current.GetService(); } } public IFocusManager FocusManager { get { return Locator.Current.GetService(); } } public abstract ModifierKeys Modifiers { get; } private void ProcessRawEvent(RawKeyEventArgs e) { Interactive interactive = FocusManager.Current as Interactive; if (interactive != null) { switch (e.Type) { case RawKeyEventType.KeyDown: interactive.RaiseEvent(new KeyEventArgs { RoutedEvent = Control.KeyDownEvent, Device = this, Key = e.Key, Text = e.Text, Source = interactive, OriginalSource = interactive, }); break; } } } } }