using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Windows.Foundation.Metadata; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Input; namespace Monaco.Helpers { public delegate void WebKeyEventHandler(CodeEditor sender, WebKeyEventArgs args); public sealed class WebKeyEventArgs { public int KeyCode { get; set; } // TODO: Make these some sort of flagged state enum? public bool CtrlKey { get; set; } public bool ShiftKey { get; set; } public bool AltKey { get; set; } public bool MetaKey { get; set; } public bool Handled { get; set; } } [AllowForWeb] public sealed class KeyboardListener { private WeakReference parent; public KeyboardListener(CodeEditor parent) // TODO: Make Interface for event usage { this.parent = new WeakReference(parent); } /// /// Called from JavaScript, returns if event was handled or not. /// /// /// /// /// /// /// public bool KeyDown(int keycode, bool ctrl, bool shift, bool alt, bool meta) { if (parent.TryGetTarget(out CodeEditor editor)) { return editor.TriggerKeyDown(new WebKeyEventArgs() { KeyCode = keycode, // TODO: Convert to a virtual key or something? CtrlKey = ctrl, ShiftKey = shift, AltKey = alt, MetaKey = meta }); } return false; } } }