using Clave; namespace Glass.UnitTests { /// /// A keyboard manager with one control focused, fed keys through a tracker the way a host would. /// public class FocusedKeys { public readonly KeyboardManager Manager = new KeyboardManager(); public readonly KeyTracker Tracker = new KeyTracker(); public FocusedKeys(Control control) : this(control, control) { } /// /// Puts in the manager and focuses , which is somewhere /// beneath it. /// public FocusedKeys(Control root, Control focused) { Manager.Controls.Add(root); Manager.TrySetFocus(focused); } /// /// Puts in a manager and enters it, as whatever opens a dialog would. /// public static FocusedKeys Enter(Control scope) { var returnMe = new FocusedKeys(scope, null); returnMe.Manager.EnterScope(scope); return returnMe; } public bool Press(KeyCode key) { return Manager.KeyDown(Tracker.KeyDown(key, KeyCode.None, isRepeat: false)); } public bool Repeat(KeyCode key) { return Manager.KeyDown(Tracker.KeyDown(key, KeyCode.None, isRepeat: true)); } public bool Release(KeyCode key) { return Manager.KeyUp(Tracker.KeyUp(key)); } } }