using System; using System.Collections.Generic; using System.Windows.Forms; using CefSharp; namespace prBrowser { internal class KeyboardHandler : IKeyboardHandler { private MainForm myForm; public static List Hotkeys = new List(); public static void AddHotKey(Form form, Action function, Keys key, bool ctrl = false, bool shift = false, bool alt = false) { Utils.AddHotKey(form, function, key, ctrl, shift, alt); Hotkeys.Add(new SharpHotKey(function, key, ctrl, shift, alt)); } public KeyboardHandler(MainForm form) { myForm = form; } public bool OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut) { return false; } public bool OnKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey) { if (type == KeyType.RawKeyDown) { bool ctrlDown = ((int)modifiers).IsBitmaskOn(4); bool shiftDown = ((int)modifiers).IsBitmaskOn(2); bool altDown = ((int)modifiers).IsBitmaskOn(8); foreach (SharpHotKey key in Hotkeys) { if (key.KeyCode == windowsKeyCode && key.Ctrl == ctrlDown && key.Shift == shiftDown && key.Alt == altDown) { myForm.InvokeOnParent(delegate { key.Callback(); }); } } } return false; } } }